Set Gateways


It’s been a while since I had some new network implementation project which required changing a few dozen of gateways. Because of older OSs I haven’t been using netroute cmdlets I ended up with script leveraging old WMI cmdlets.
I couldn’t make invoke-cimmethod -methodname setgateways to work. Parameter should be @{ DefaultIPGateway = ‘some IP’} wright?
The error I’m receiving is
“Unable to cast object of type ‘System.String’ to type ‘System.Collections.IList’”


Try this
$gw = @(‘’)
$mt = @([uint16]1)
Get-CimInstance -ClassName Win32_NetworkAdapterConfiguration -Filter “Index = 2” | Invoke-CimMethod -MethodName SetGateWays -Arguments @{DefaultIPGateway = $gw; GatewayCostMetric = $mt}

You have to supply an array of addresses for the gateway and metric

Thank you very much. Can’t believe solution was just a cast away… It does say ‘StringArray’ for DefaultIPGateway parameter of SetGateways method (and ‘UInt16Array’ for GatewayMetric)… I should read more carefully.

Thanks again!!!