Author Posts

February 21, 2016 at 1:09 am

Hello!

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'"

I

February 21, 2016 at 2:11 am

Try this
$gw = @('10.10.54.1')
$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

February 21, 2016 at 5:30 am

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!!!