DnsClientServerAddress on remote servers

Hello

Super new and have been tasked with attempting to obtain primary and secondary dns addresses on +100 servers (single domain).

New-CimSession -ComputerName Server01, Server02 -Name Test

Get-CimSession -Name Test

Get-DnsClientServerAddress -CimSession Test

The credentials used to access the remote servers are the same as the one used to run the ps commands.

 

 

 

Since you are new, it’s vital that you ramp up first before going down this path and unnecessarily frustrating yourself. There is plenty of no cost video training via:

Microsoft Virtual Academy
https://mva.microsoft.com/training-topics/powershell#!jobf=IT%20Pros&lang=1033

TechNet Virtual Labs
https://www.microsoft.com/en-us/evalcenter/my-virtual-labs
https://labondemand.com/Event/MSHandsOnLabs/Home

YouTube
https://www.youtube.com/results?search_query=beginning+powershell

… and there are tons of no cost eBooks via this site and more.

The Re-Launch of the PowerShell.org Free eBooks https://powershell.org/category/books

Free PowerShell eBooks
https://blogs.technet.microsoft.com/pstips/2014/05/26/free-powershell-ebooks

Windows PowerShell Survival Guide
https://social.technet.microsoft.com/wiki/contents/articles/183.windows-powershell-survival-guide.aspx

The cmdlets have a -Credential parameter for you to use to reach the hosts.

New-CimSession -Credential

Also, look to the following cmdlets for the other information.

Resolve-DnsName
Get-DnsServerResourceRecord

There are even pre-built scripts that you can use as is or tweak as needed for your needs.

Example:

https://www.powershellgallery.com/packages?q=dns https://gallery.technet.microsoft.com/Gather-DNS-settings-from-fec23eaa https://4sysops.com/archives/get-dns-server-ips-using-powershell

It could be a simple as this…

# Set the admin credential
$Creds = Get-Credential -Credential 'domain\username'
# Get ADDS computers properties for DNS information
'server01','server02','server03' | 
ForEach {
    "Processing computername $_"
    Invoke-Command -ComputerName $_ -ScriptBlock {
    # Get the DNS address information for the target
    Get-DnsClientServerAddress
    } -Credential $Creds
    "`n" # line break
}

I am using a typed list here, but this could have been called from a file or even live from ADDS.
You can drive deeper by using the network card config on the host as well. See this…

https://blogs.technet.microsoft.com/danstolts/2012/01/using-powershell-to-get-or-set-networkadapterconfiguration-view-and-change-network-settings-including-dhcp-dns-ip-address-and-more-dynamic-and-static-step-by-step

IMO, What he already have is the best way to do it.

$Session = New-CimSession -ComputerName Server01, Server02
Get-DnsClientServerAddress -CimSession $Session