使用PowerShell 修改hosts

直接上代码

# author:lttr <www.cnblogs.com/GoCircle> 
# date:2019-08-09
[CmdletBinding()] param ( [Parameter(Mandatory
=$true,Position=0)][string]$IPURL ) if((Get-Content $env:windir\System32\drivers\etc\hosts |?{$_ -match "/s$IPURL"}) -eq $null){ "`n$IPURL" | Out-File -FilePath "$env:windir\System32\drivers\etc\hosts" -Append -encoding ascii Write-Host "修改成功!" }else{ Write-Host "host文件中存在该配置信息。" }

 

 

posted @ 2019-07-26 14:55  听雨的人  阅读(1492)  评论(0编辑  收藏  举报