Change DHCP ip address to Static IP Using powershell
hello ,
i used below script change dhcp ip static on multiple servers. nut no luck :(
$nics = get-wmiobject win32_networkadapterconfiguration -computername (gc .\servers.txt) | where{$_.ipenabled -eq $true -and $_.dhcpenabled -eq $true}
foreach($nic in $nics) {
$ip = ($nic.ipaddress[0])
$gateway = $nic.defaultipgateway
$subnet = $nic.ipsubnet[0]
$dns = $nic.dnsserversearchorder
$nic.enablestatic($ip, $subnet)
$nic.setgateways($gateway)
$nic.setdnsserversearchorder($dns)
$nic.setdynamicdnsregistration("false")
}
when execute on windows 2000 , windows 2003 server disconnecting not able connect server ip or server name .
please provide some solution or alternate script hel me update dhcp ip static.
thanks, jeevan
hi jeevan,
thanks posting.
since there multiple servers stored in .\servers.txt file, need to add cmdlet "foreach-object" script.
to change dhcp ip address static ip, please try script below modify script function set-static:
function set-static { param($name) $nics = get-wmiobject -class win32_networkadapterconfiguration -computername $name | {$_.ipenabled -eq $true -and $_.dhcpenabled -eq $true} foreach($nic in $nics) { $dnsservers = $nic.dnsserversearchorder $nic.setdnsserversearchorder($dnsservers) $nic.setdynamicdnsregistration("true") $ipaddr = ($nic.ipaddress[0]) $gateway = $nic.defaultipgateway $netmask = $nic.ipsubnet[0] $nic.enablestatic($ipaddr, $netmask) $nic.setgateways($gateway)} } $array = import-csv "c:\servers.txt"
$array | foreach-object {set-static -name $_.host}
the input txt file c:\servers.txt listed this:
host
pa-vcs-int
i hope helps.
we trying better understand customer views on social support experience, participation in interview project appreciated if have time.
helping make community forums great place.
Windows Server > Windows PowerShell
Comments
Post a Comment