安装 PowerShell 7:winget install --id Microsoft.PowerShell --source winget ,或者在 https://learn.microsoft.com/en-us/powershell/scripting/install/install-powershell-on-windows?view=powershell-7.5 下载 MSI 文件安装。
将下面内容保存到 update_gh_hosts.ps1,管理员权限运行 PowerShell 7,进入到目录执行 .\update_gh_hosts.ps1。
# 必须以管理员身份运行
$currentPrincipal = [Security.Principal.WindowsPrincipal][Security.Principal.WindowsIdentity]::GetCurrent()
if (-not $currentPrincipal.IsInRole([Security.Principal.WindowsBuiltinRole]::Administrator)) {
Write-Host "错误:请右键点击脚本并选择 '以管理员身份运行' (Run as Administrator)" -ForegroundColor Red