1. 程式人生 > >powershell 腳本設置DNS

powershell 腳本設置DNS

powershell更改dns

#!powershell
$adapter = Get-NetAdapter |?{$_.InterfaceDescription -ne "Microsoft KM-TEST Loopback Adapter"}
if ($adapter -ne $null) 
{
    $adapter | Rename-NetAdapter -NewName "Eth"
     disable-NetAdapterBinding -Name "Eth" -ComponentID ms_tcpip6
     netsh interface ipv4 set dns name="Eth" source=static address=114.114.114.114 primary
     netsh interface ipv4 add dnsserver name="Eth" address=8.8.8.8 index=2
     netsh interface ipv4 add dnsserver name="Eth" address=202.96.209.133 index=3
}

以上就是powershell設置dns地址的腳本,適用於powershell 4及以上版本


windwos 2008 更改DNS方法:

$wmi=get-wmiobject -class win32_networkadapterconfiguration -filter ipenabled=true -computername 計算機名
$wmi.SetDNSServerSearchOrder(‘8.8.8.8‘)



本文出自 “zengestudy” 博客,請務必保留此出處http://zengestudy.blog.51cto.com/1702365/1928929

powershell 腳本設置DNS