以下介绍配置IP和网关地址,同时禁用IPv6.
function Set_IPAddress{
Param(
[Parameter(Mandatory=$true)]
[string]$IPAddress,
[Parameter(Mandatory=$true)]
[string]$IPGateway,
[Parameter(Mandatory=$true)]
$InterfaceIndex,
[Parameter(Mandatory=$true)]
$InterfaceName
)
# Configuration IP Gateway and DNS
New-NetIPAddress -InterfaceIndex $InterfaceIndex -IPAddress $IPAddress -AddressFamily IPv4 -PrefixLength 24 -DefaultGateway $IPGateway
Set-DnsClientServerAddress -InterfaceIndex $InterfaceIndex -ServerAddresses $IPAddress
# Disable IPv6
Disable-NetAdapterBinding -Name $InterfaceName -ComponentID ms_tcpip6
}
$IPAddress = "10.1.1.1"
$IPGateway = "10.1.1.254"
$InterfaceIndex = (Get-NetAdapter).InterfaceIndex
$InterfaceName = (Get-NetAdapter).Name
Set_IPAddress -InterfaceIndex $InterfaceIndex -InterfaceName $InterfaceName -IPAddress $IPAddress -IPGateway $IPGateway