powershell 从https://github.com/StevenBlack/hosts更新Windows主机文件

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了powershell 从https://github.com/StevenBlack/hosts更新Windows主机文件相关的知识,希望对你有一定的参考价值。

<#
Tested on Win7-64x and Powershell v5 & v4
maybe Set-ExecutionPolicy Unrestricted
msenturk - 24.02.2016
#>

# Create temp folder..
New-Item -ItemType Directory -Force -Path 'C:\Hosts\'
Set-Location C:\Hosts\
wget 'https://raw.githubusercontent.com/StevenBlack/hosts/master/hosts' -OutFile hosts
# Clean up and remove dublicates ..
Get-Content hosts | Where { $_ -notmatch "\#" } | Where {$_.trim() -ne " " } | Sort-Object -Unique | Set-Content final
# Back-up and Update hostsfile..
Copy-Item -Recurse "C:\Windows\System32\drivers\etc\hosts" -Destination "C:\Windows\System32\drivers\etc\hosts.bak"
Copy-Item -Recurse ".\final" -Destination "C:\Windows\System32\drivers\etc\hosts"
# FlushDNS..
CMD.EXE /C "ipconfig /flushdns" 
Write-Host "`nHosts File Updated" -ForegroundColor Green
rm .\final -Recurse

以上是关于powershell 从https://github.com/StevenBlack/hosts更新Windows主机文件的主要内容,如果未能解决你的问题,请参考以下文章

powershell 使用powershell #powershell从zip文件中删除文件

如何从其他powershell脚本调用powershell脚本并且脚本是在powershell对象而不是文件中分配的

powershell 从PowerShell访问SQLite

powershell 从Network Drives Powershell复制

powershell 从powershell将数据插入表中

powershell 从PowerShell动态加载.Net程序集