November 20, 2012

Active Directory - Getting network settings from remote computers

How to get network settings from multiple domain member servers and computers?

I am going to collect next configuration and output it to the txt file:

DNSHostName
Description
IPAddress
IpSubnet
MACAddress
,DefaultIPGateway
DNSServerSearchOrder
WINSPrimaryServer
WINSSecondaryServer

Complete list of objects: here

Powershell command syntax for multiple computer objects:

Get-WmiObject Win32_NetworkAdapterConfiguration -comp (Get-ADComputer -filter * -SearchScope Subtree -searchbase 'OU=OrganizationUnit,dc=example,dc=com'|select –expand Name) | Where-Object { $_.IPAddress -ne $null } | Select-Object DNSHostName,Description,IPAddress,IpSubnet,MACAddress,DefaultIPGateway,DNSServerSearchOrder,WINSPrimaryServer,WINSSecondaryServer | ft -wrap | out-file C:\NetworkSettings.txt -width 1000

Where 'OU=OrganizationUnit,dc=example,dc=com' - organization unit where we perform lookup, C:\NetworkSettings.txt - file where stores output. 

For one computer you can use next command: 

Get-WmiObject -ComputerName Name_of_computer Win32_NetworkAdapterConfiguration | Where-Object { $_.IPAddress -ne $null } | Select-Object DNSHostName,Description,IPAddress,IpSubnet,MACAddress,DefaultIPGateway,DNSServerSearchOrder,WINSPrimaryServer,WINSSecondaryServer | ft -wrap

Where Name_of_computer is name of remote computer. 

Also $ErrorActionPreference = "silentlycontinue" can be used


Useful links:
http://gallery.technet.microsoft.com/scriptcenter/Get-Network-Information-of-6d07766f
http://gallery.technet.microsoft.com/scriptcenter/PowerShell-Output-DNS-and-d935a44c
http://www.windowsitpro.com/blog/powershell-with-a-purpose-blog-36/scripting-languages/why-get-wmiobject-cant-accept-computer-names-from-the-pipeline-137375

No comments:

Post a Comment