idwma 当前离线
少校
$IP_URL = "127.0.0.1 www.bing.com" if ((Get-Content $env:windir\System32\drivers\etc\hosts | ?{ $_ -match "$($IP_URL -replace '\s+','\s+')" }) -eq $null) { "$IP_URL" | ac "$env:windir\System32\drivers\etc\hosts" echo "已添加!" } else { echo "已存在" }复制代码
TOP
$IP_URL = "127.0.0.1 www.bing.com" $IP_URL11 = "127.0.0.1 www.bing.com" $IP_URL -match $IP_URL11 $IP_URL -match "$($IP_URL11 -replace '\s+','\s+')"复制代码
$IP_URL = @( "127.0.0.1 www.bing.com" "127.0.0.1 www.sina.com" ) $IP_URL -notmatch "$((Get-Content $env:windir\System32\drivers\etc\hosts | ?{ $_ -match "$($IP_URL -join '|')"}) -join '|')"|ac "$env:windir\System32\drivers\etc\hosts"复制代码
$IP_URL = @( "127.0.0.1 www.bing.com" "127.0.0.1 www.sina.com" ) $a=(Get-Content "$env:windir\System32\drivers\etc\hosts" | ?{ $_ -match "$($IP_URL -join '|')"}) -join '|' if ($a -eq '') { $IP_URL | ac "$env:windir\System32\drivers\etc\hosts" echo "已添加!" } else { $IP_URL -notmatch "$a" | ac "$env:windir\System32\drivers\etc\hosts" echo "已存在" }复制代码
$Hosts = "$env:windir\System32\drivers\etc\hosts" $a=gc $Hosts $urls = @( "www.baidu.com" "www.bing.com" ) | foreach{ if($a[-1] -ne ''){ac $hosts ''}elseif ((gc $Hosts | Select-String $_) -eq $null) { ac $hosts "127.0.0.1 $_" } }复制代码