Save all the network details for a group of machines into text files

Posted: March 14, 2012 in Networking, Scripts, VMware

I recently did a VM migration from ESX 3.0.3 to ESXi 5. As part of the migration, we were upgrading tools and VM hardware. This in a lot of cases will cause the gest to lose it’s network configs. With that in mind, I created the following quick PowerSheel script to go out and retrieve the target VMs network configs and save them to text files, so that we could go back and reset them if needed.

It will also create a test file called Failed.txt for anything it was unable to query. So I was able to use that as the next group in SererList.txt and then try using different credentials on the next run.

$Creds = Get-Credential

$Servers = Get-Content C:\Scripts\NetworkConfig\ServerList.txt
Remove-Item C:\Scripts\NetworkConfig\Failed.txt

ForEach ($Server in $Servers){

Remove-Item C:\Scripts\NetworkConfig\$Server-IPConfig.txt
$NICs = $null
$NICs = Get-WMIObject Win32_NetworkAdapterConfiguration -Credential $creds -ComputerName $Server | Where { $_.IPEnabled -eq $true }

If ($NICs -ne $null){
ForEach ($NIC in $NICs){

$NIC | Select DHCPEnabled, IPAddress, IPSubnet, DefaultIPGateway, DNSServerSearchOrder, WINSPrimaryServer, WINSSecondaryServer, MACAddress | Out-File C:\Scripts\NetworkConfig\$Server-IPConfig.txt -Append

If ($NICs -eq $null){
$Server | Out-File C:\Scripts\NetworkConfig\Failed.txt -Append


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s