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

Add-NetworkAdapterDNS

Synopsis

Adds the specified DNS server address to the configuration of a network adapter on a local or remote computer.

Syntax

  • Add-NetworkAdapterDNS [-Name] [-DNSServer] [-Position] [-ComputerName] [-Credential]
  • Add-NetworkAdapterDNS [-MACAddress] [-DNSServer] [-Position] [-ComputerName] [-Credential]

Description

The Add-NetworkAdapterDNS cmdlet is used to add DNS server addresses to the configuration of 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.
  • DNSServer The DNS server to add.
  • Position The position in which to add the DNS server address. If the parameter is not specified or an invalid position is given (such as position 4 on an adapter with only primary and secondary DNS addresses configured) the address will be added with the lowest valid position.
  • MACAddress The MAC address of the network adapter to configure. This parameter cannot be used when the name parameter has been specified.
  • 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

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

Outputs

Add-NetworkAdapterDNS makes changes directly to Windows and does not output any Powershell objects.

Notes

The Add-NetworkAdapterDNS 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 add the DNS server address 192.68.1.44 to adapter "Local Area Connection". Because the position parameter has not been specified the DNS server will be given the lowest priority:

C:\PS>Add-NetworkAdapterDNS "Local Area Connection" -DNSServer 192.168.1.44

Example 2

This command will add the DNS server address 192.68.1.45 to adapter "Local Area Connection". The position parameter has been used to specify this address as the secondary DNS server.

C:\PS>Add-NetworkAdapterDNS "Local Area Connection" -DNSServer 192.168.1.45 -Position 2

Example 3

Add-NetworkAdapterDNS can be used in conjunction with the Get-NetworkAdapter cmdlet. In this example, Get-NetworkAdapter fetches all the network adapters on the remote computer PC01 and Add-NetworkAdapterDNS adds 192.68.1.45 as the new primary DNS server on each adapter.

C:\PS>Get-NetworkAdapter | Add-NetworkAdapterDNS -DNSServer 192.168.1.45 -Position 1