This cmdlet is part of the Vexasoft Cmdlet Library. You can download it now or click here to find out more.

Set-NetworkAdapterGateway

Synopsis

Sets the default and additional gateway addresses of a network adapter on a local or remote computer.

Syntax

  • Set-NetworkAdapterGateway [-Name] [-Gateway] [-ComputerName] [-Credential]
  • Set-NetworkAdapterGateway [-MACAddress] [-Gateway] [-ComputerName] [-Credential]

Description

The Set-NetworkAdapterGateway cmdlet is used to set the default gateway and any additional gateways used by a network adapter on a local or remote computer. Adapters can be identified by name or MAC address.

Parameters

  • Name The name of the network adapter to configure. This parameter cannot be used when the MACAddress parameter has been specified.
  • MACAddress The MAC address of the network adapter to configure. This parameter cannot be used when the name parameter has been specified.
  • Gateway The gateway addresses to be assigned to the network adapter. When specifying multiple addresses to this parameter, each is given equal priority.
  • ComputerName The computer against which to run the cmdlet. By default this cmdlet will be populated with the name of the local computer.
  • Credential The credentials under which to run the cmdlet. By default this cmdlet will run as the current user. Using this parameter and the Get-PSCredential cmdlet you can specify an alternate set of credentials under which to execute this command.

Inputs

Set-NetworkAdapterGateway accepts the output of Get-NetworkAdapter as an input object. The Name, MACAddress and ComputerName parameters each accept pipeline input by property name.

Outputs

Set-NetworkAdapterGateway makes changes directly to Windows and does not output any Powershell objects.

Notes

The Set-NetworkAdapterGateway cmdlet requires that the Remote Registry and RPC services are started on the computer it is trying to access and that DNS services are available to resolve target host names.

Example 1

This command will set the default gateway on network adapter "Local Area Connection" on the local computer to 192.168.0.44:

C:\PS>Set-NetworkAdapterGateway "Local Area Connection" -Gateway 192.168.0.44

Example 2

This command will set the network adapter "Local Area Connection" on the remote computer PC01 to use 192.168.0.44 and 192.168.0.45:

C:\PS>Set-NetworkAdapterGateway "Local Area Connection" -Gateway 192.168.0.44, 192.168.0.45 -Computer PC01

Example 3

Set-NetworkAdapterGateway can also be used in conjunction with the Get-NetworkAdapter cmdlet. This command copies the gateways used by the local computer and sets them on adapters of the same name on remote computer PC01:

C:\PS>Get-NetworkAdapter | Set-NetworkAdapterGateway -Computer PC01