要编辑 PowerShell 脚本以配置 Windows 主机的 DNS 为指定的两个 IP 地址,可以按照以下步骤进行操作:

  1. 打开任意文本编辑器,如 Notepad 或 Visual Studio Code。

  2. 在编辑器中创建一个新的文件。

  3. 在文件中输入以下内容:

$dnsServers = 'IP地址1', 'IP地址2'
$interfaceIndex = (Get-NetAdapter | Where-Object {$_.Status -eq 'Up'}).InterfaceIndex
$interface = Get-NetAdapter -InterfaceIndex $interfaceIndex
Set-DnsClientServerAddress -InterfaceIndex $interfaceIndex -ServerAddresses $dnsServers

将'IP地址1'和'IP地址2'替换为要设置的 DNS 服务器的实际 IP 地址。

  1. 将文件保存为 .ps1 文件扩展名,例如'configure_dns.ps1'。

  2. 打开 PowerShell 控制台。

  3. 使用以下命令启用脚本执行权限:

Set-ExecutionPolicy RemoteSigned
  1. 使用以下命令导航到包含脚本文件的目录:
cd C:\脚本文件路径

将'C:\脚本文件路径'替换为实际脚本文件所在的目录路径。

  1. 运行以下命令以执行脚本:
.\configure_dns.ps1

脚本将在 Windows 主机上配置 DNS 为指定的两个 IP 地址。

如何使用 PowerShell 脚本配置 Windows 主机 DNS 为指定 IP 地址

原文地址: https://www.cveoy.top/t/topic/qmXB 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录