Set Gateways

This topic contains 2 replies, has 2 voices, and was last updated by Profile photo of Milos Ostojic Milos Ostojic 7 months, 1 week ago.

Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • #35501
    Profile photo of Milos Ostojic
    Milos Ostojic
    Participant

    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

    #35502

    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

    #35504
    Profile photo of Milos Ostojic
    Milos Ostojic
    Participant

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

Viewing 3 posts - 1 through 3 (of 3 total)

You must be logged in to reply to this topic.