Get DNS records

Ask your Windows 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.
User avatar
JohnTitor
Posts: 153
Joined: Fri Nov 17, 2017 8:49 pm

Re: Get DNS records

Post by JohnTitor » Tue Mar 05, 2019 5:34 pm

So going back

(Get-WmiObject Win32_NetworkAdapterConfiguration -FIlter 'IPEnabled=True').DNSDomainSuffixSearchOrder

Only one of my adapters had an IP

It still returned duplicates

I just want all of my 20+ DNSs in a variable to use

User avatar
jvierra
Posts: 13615
Joined: Tue May 22, 2007 9:57 am
Contact:

Re: Get DNS records

Post by jvierra » Tue Mar 05, 2019 7:15 pm

If you do this:

Get-WmiObject Win32_NetworkAdapterConfiguration -FIlter 'IPEnabled=True'

What do you see?

User avatar
JohnTitor
Posts: 153
Joined: Fri Nov 17, 2017 8:49 pm

Re: Get DNS records

Post by JohnTitor » Tue Mar 05, 2019 10:16 pm

DNS2.png
DNS2.png (27.05 KiB) Viewed 885 times

User avatar
jvierra
Posts: 13615
Joined: Tue May 22, 2007 9:57 am
Contact:

Re: Get DNS records

Post by jvierra » Wed Mar 06, 2019 2:07 am

What does this show:

Get-WmiObject Win32_NetworkAdapterConfiguration -FIlter 'IPEnabled=True'| select name,DNSDomainSuffixSearchOrder

User avatar
JohnTitor
Posts: 153
Joined: Fri Nov 17, 2017 8:49 pm

Re: Get DNS records

Post by JohnTitor » Wed Mar 06, 2019 8:38 am

I did forget to add, it showed one under DNSDomain

This appears duplicates
Snag_5c52f2.png
Snag_5c52f2.png (12.7 KiB) Viewed 847 times

User avatar
jvierra
Posts: 13615
Joined: Tue May 22, 2007 9:57 am
Contact:

Re: Get DNS records

Post by jvierra » Wed Mar 06, 2019 9:12 am

You are returning two adapters. That will give you duplicates. You can only expand arrays on one adapter to get only that adapters settings.

User avatar
JohnTitor
Posts: 153
Joined: Fri Nov 17, 2017 8:49 pm

Re: Get DNS records

Post by JohnTitor » Wed Mar 06, 2019 11:41 am

This finally gives me one
Get-WmiObject Win32_NetworkAdapterConfiguration | Where-Object {($_.IPEnabled -eq $true) -and ($_.DHCPEnabled -eq $true)} | select name,DNSDomainSuffixSearchOrder

There is also a VM adapter enabled, BUT it doesn't have any DNSDomains attached to it..

Regardless, I'm picking up what you're putting down.

Locked