Hello Script expert,
I have 100 + servers need to change to the new gateway. I would like to ping the new gateway from servers first, then look through the server's NIC to see if the NIC is on specific subnet xxx.xxx. with the old gateway then change to the new gateway, do nothing if server(s) have no gateway.
I have the script but only check for the NIC have IP address on specific subnet. When tested, sometime it throw out an error :
"Get-WmiObject: Cannot validate argument on parameter 'ComputerName'. The argument is null or empty."
Here is the script:
_______________________________________________________________________
$DefGateway = "xxx.xxx.xxx.xxx"$server_list = get-content "C:\server.txt"
foreach($server in $server_list)
{
$nics = Get-WmiObject -Class Win32_NetworkAdapterConfiguration -ComputerName $server -Filter "IPEnabled=TRUE"
foreach($nic in $nics)
{
if($nic.ipaddress -match "xxx.xxx." & ) s
{
$nic.SetGateways($DefGateway)
}
}
}
________________________________________________________________
Here is the script to ping from servers:
$servers = Get-Content "C:\Ping.txt"Invoke-Command -ComputerName $servers -ScriptBlock { cmd /c ping -n xxx.xxx.xxx.xxx }
_______________________________________________________________________
Again, it throw an error: "Get-WmiObject: Cannot validate argument on parameter 'ComputerName'. The argument is null or empty."
I'm really bad with scripting. Please help!
Thanks in advance for the help from all the experts here.
DTNG
- Edited by dtng Thursday, August 20, 2015 8:31 PM