Problem
You want to assign a static IP address to a computer.
Solution
Use the Win32_NetworkAdapterConfiguration WMI class to manage network settings for a computer:
$description = "Linksys WirelessG USB" $staticIp = "192.168.1.100" $subnetMask = "255.255.255.0" $gateway = "192.168.1.1"
$adapter = GetWmiObject Win32_NetworkAdapterConfiguration –Computer LEEDESK |
WhereObject { $_.Description –match $description}
$adapter.EnableStatic($staticIp, $subnetMask)
$adapter.SetGateways($gateway, [UInt16] 1)
Discussion
When managing network settings for a computer, the Win32_NetworkAdapter Configuration WMI class requires that you know the description of the network adapter. Obtain that by reviewing the output of GetWmiObject Win32_ NetworkAdapterConfiguration –Computer <ComputerName>:
PS >GetWmiObject Win32_NetworkAdapterConfiguration –Computer LEEDESK
(...) DHCPEnabled : True IPAddress : {192.168.1.100} DefaultIPGateway : {192.168.1.1} DNSDomain : hsd1.wa.comcast.net. ServiceName : USB_RNDIS Description : Linksys WirelessG USB Network Adapter with (...) Index : 13 (...)
Knowing which adapter you want to renew, you can now call methods on that object as illustrated in the solution. To enable DHCP on an adapter again, use the EnableDHCP() method:
PS >$adapter.EnableDHCP()