1

Good day everyone,

Trying to write a simple script that will find the friendly name of the Ethernet Adapter on a given machine and pass this string to the cmdlet 'Set-DnsClientServerAddress' so that I can change the DNS server settings on the Ethernet interface only.

I have tried this:

$EthAdapter = Get-NetAdapter -Name Ether* | select Name | Set-DnsClientServerAddress -ServerAddresses 192.168.0.1, 192.168.0.2 -PassThru 

And get the error:

Set-DnsClientServerAddress : Parameter set cannot be resolved using the specified named parameters. At C:\users\zsnow\Desktop\setup.ps1:5 char:59 + ... lect Name | Set-DnsClientServerAddress -ServerAddresses 192.168.0.1, ... + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : InvalidArgument: (@{Name=Ethernet 2}:PSObject) [Set-DnsClientServerAddress], ParameterBindingException + FullyQualifiedErrorId : AmbiguousParameterSet,Set-DnsClientServerAddress

I have tried this:

$EthAdapter = Get-NetAdapter -Name Ether* | select Name Set-DnsClientServerAddress -InterfaceAlias $EthAdapter -ServerAddresses 192.168.0.1, 192.168.0.2 -PassThru 

And get this error:

Set-DnsClientServerAddress : No MSFT_DNSClientServerAddress objects found with property 'InterfaceAlias' equal to '@{Name=Ethernet 2}'. Verify the value of the property and retry. At C:\users\zsnow\Desktop\setup.ps1:6 char:1 + Set-DnsClientServerAddress -InterfaceAlias $EthAdapter -ServerAddress ... + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : ObjectNotFound: (@{Name=Ethernet 2}:String) [Set-DnsClientServerAddress], CimJobException + FullyQualifiedErrorId : CmdletizationQuery_NotFound_InterfaceAlias,Set-DnsClientServerAddress

Any assistance would be appreciated.

2 Answers 2

0

Give this a try.

$EthAdapters = Get-NetAdapter -Name Ether* foreach ($EthAdapter in $EthAdapters) { Set-DnsClientServerAddress -ServerAddresses 192.168.0.1, 192.168.0.2 -PassThru -InterfaceAlias $EthAdapter.name -Verbose } 
0

in your original post, you either need "select -expandproperty name" instead of "select name" in your first command, or $ethadapter.name in the second command. one or the other, not both. the way you have it written, $ethadapter is an array with one column called "name", so your dns command is trying to make a change on an adapter named, literally '@{Name=Ethernet 2}'. which doesn't exist.

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.