Query DNS Suffix for this Connection

Ask your PowerShell-related questions, including questions on cmdlet development!
Forum rules
Do not post any licensing information in this forum.

Any code longer than three lines should be added as code using the 'Select Code' dropdown menu or attached as a file.
This topic is 14 years and 10 months old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.
Locked
User avatar
litog
Posts: 8
Last visit: Thu May 21, 2009 5:28 am

Query DNS Suffix for this Connection

Post by litog »

Hello,

I am attempting to query all computers with a specific role or OS Name, and look for a value to see if its in it then report it. For example I want to search all VISTA computers for "domain.net" in the "DNS suffix for this connection" field. This isn't the Suffix search order. I found the correct wmi object and it's called "DNSDomain". I've put this script together but it doesn't seem to be correct.

$servers = Get-QADComputer -OSName "*2000*"

each ($servers in $dns) {

$dns = Get-WmiObject Win32_NetworkAdapterconfiguration | { $_.'DNSDomain' -icontains "domain.com"}
}

Does something stand out to anyone on what I have wrong?

Thanks
User avatar
jhicks
Posts: 1789
Last visit: Mon Oct 19, 2015 9:21 am

Query DNS Suffix for this Connection

Post by jhicks »

You don't need to quote the property name, although that shouldn't make a difference. What doesn't seem to work? Are you getting no values? I would first make sure I'm getting results then filter.I can see that your syntax is a little foobar as well.$servers = Get-QADComputer -OSName "*2000*"

foreach ($server in $servers) {

Get-WmiObject Win32_NetworkAdapterconfiguration -computer $server -filter "DNSDomain='domain.com'"}
}
User avatar
litog
Posts: 8
Last visit: Thu May 21, 2009 5:28 am

Query DNS Suffix for this Connection

Post by litog »

Ouch. :-)

I ran get-wmiobject Win32_NetworkAdapterConfiguration DNSDomain and did get results. It listed all the network adapter and I did find the adapter with the domain.com suffix, but when I add the filter

get-wmiobject Win32_NetworkAdapterConfiguration -filter "DNSDomain='domain.com'"

it just sits at a >> prompt. I tried several different combinations but just receive an Invalid Query error.

User avatar
jhicks
Posts: 1789
Last visit: Mon Oct 19, 2015 9:21 am

Query DNS Suffix for this Connection

Post by jhicks »

The >> means PowerShell's parser is expecting more to complete the command like a closing } or ". What you've pasted works for me. If you still get errors, paste more of your actual command.
User avatar
litog
Posts: 8
Last visit: Thu May 21, 2009 5:28 am

Query DNS Suffix for this Connection

Post by litog »

I must have typed something wrong earlier because I tried it again copy and paste and when I added the filter I was able to get further.
Here is the script exactlyl as I have it;

$servers = Get-QADComputer -OSName "*2000*"

foreach ($server in $servers) {

Get-WmiObject Win32_NetworkAdapterconfiguration -computer $server -filter "DNSDomain='neto'"
}

Notice that the domain name is a just neto since at one point it was a single lable domain name. That's been changed and there were some manual entries in this field that I want to get rid of, hence the script. When I run this I get the following error;


Invalid parameter
At :line:5 char:13
+ Get-WmiObject <<<< Win32_NetworkAdapterconfiguration -computer $server -filter "DNSDomain='neto'"
User avatar
joel.delatorre
Posts: 83
Last visit: Tue Jan 17, 2017 9:26 am

Query DNS Suffix for this Connection

Post by joel.delatorre »

You need to get to the Name property of the $server object. Use $($server.name) instead of just $server in your WMI command
User avatar
litog
Posts: 8
Last visit: Thu May 21, 2009 5:28 am

Query DNS Suffix for this Connection

Post by litog »

Perfect. That worked, thanks to all of you.

Is there a way to have it continue if it gets an access denied message? Right now if stops.

Thanks
User avatar
jhicks
Posts: 1789
Last visit: Mon Oct 19, 2015 9:21 am

Query DNS Suffix for this Connection

Post by jhicks »

add this to your Get-WMIObject expression:-ea "SilentlyContinue"
This topic is 14 years and 10 months old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.
Locked