Here is a simple example illustrating how you assign IP address, gateway, and DNS server to a network adapter. The script lists all active network adapters, and when you select one and click OK, uses the hard-coded addresses to assign new values.

Note that the script below only pretends to do the changes. Remove the -WhatIf parameter to actually assign new values:

$NewIP = '192.168.2.12'
$NewGateway = '192.168.2.2'
$NewDNS = '8.8.8.8'
$Prefix = 24

$adapter = Get-NetAdapter |
Where-Object Status -eq 'Up' |
Out-GridView -Title 'Select Adapter to Configure' -OutputMode Single 
$index = $adapter.InterfaceIndex

New-NetIPAddress -InterfaceIndex $index -IPAddress $NewIP -DefaultGateway $NewGateway -PrefixLength $Prefix -AddressFamily IPv4 -WhatIf
Set-DNSClientServerAddress InterfaceIndex $index ServerAddresses $NewDNS -whatIf 

Twitter This Tip! ReTweet this Tip!

Anonymous