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.