Working on a project where on some servers the DHCP assigned addresses needs to be converted to static. Since there is always more than one…I needed to script it. Here is a quick way to do it via PowerShell.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
#SwitchIPtoStatic.ps1 #Get All the adapters that are on the Server $adapters = gwmi -cl win32_networkadapterconfiguration | ? {($_.ipaddress) -and $_.dhcpEnabled -eq 'True' } foreach ($adapter in $adapters) { # Get original settings $ipAddress = $adapter.IPAddress $subnetMask = $adapter.IPSubnet $dnsServers = $adapter.DNSServerSearchOrder $defaultGateway = $adapter.DefaultIPGateway # Set to static and set dns and gateway: $adapter.EnableStatic($ipAddress,$subnetMask) $adapter.SetDNSServerSearchOrder($dnsServers) $adapter.SetGateways($defaultGateway) } |
Hope this helps!