Set Gateways

Welcome Forums General PowerShell Q&A Set Gateways

This topic contains 2 replies, has 2 voices, and was last updated by

2 years, 12 months ago.

  • Author
  • #35501

    Points: 0
    Rank: Member


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


  • #35502

    Points: 0
    Rank: Member

    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

  • #35504

    Points: 0
    Rank: Member

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

The topic ‘Set Gateways’ is closed to new replies.

denizli escort samsun escort muğla escort ataşehir escort kuşadası escort