Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have this powershell script that changes the DNS settings. The below script works fine, but I want to filter by MAC address to make sure I'm changing the correct NIC.

$computer = "pc01"

$NICs = Get-WmiObject -Class Win32_NetworkAdapterConfiguration -Computer $computer -Filter "IPEnabled=TRUE"

$DNSServers = "",""

foreach($NIC in $NICs) { $NICs.SetDNSServerSearchOrder($DNSServers)

So I changed the filter to use the MACaddress. But I get the following error.

$computer = "pc01"

$NICs = Get-WmiObject -Class Win32_NetworkAdapterConfiguration -Computer $computer -Filter "MACAddress=00:1E:55:40:70:E8"

$DNSServers = "",""

foreach($NIC in $NICs) { $NICs.SetDNSServerSearchOrder($DNSServers)


Invalid query + $NICs = Get-WmiObject <<<< -Class Win32_NetworkAdapterConfiguration -Computer $computer -Filter "MACAddress=00:1E:65:40:80:E4"

You cannot call a method on a null-valued expression. + $NICs.SetDNSServerSearchOrder <<<< ($DNSServers)

share|improve this question

Try a Where clause for MAC Address: $NICs = Get-WmiObject -Class Win32_NetworkAdapterConfiguration -Computer $computer | Where {$_.MACAddress -eq $MAC}

Worked for me

share|improve this answer

Put the ' marks around what is being filtered. Using -filter is preferable over using where {} because of how the data is handled. Using the where {} involves loading all the objects from the Get-WmiObject and then filtering them. Using the -filter will do the filtering right away, so you end up with less data being worked through and less time to run the script.

$NICs = Get-WmiObject -Class Win32_NetworkAdapterConfiguration -Computer $computer -Filter "MACAddress='00:1E:55:40:70:E8'"
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.