Thursday, April 17, 2014

Reporting IP Addresses for Exchange Servers

Hi folks,

Let me share another case which made even more sure that PowerShell is really power shell.

My customer was looking to standardize DNS client settings across its Exchange servers. As the first step they wanted me to provide them with the information on how DNS settings are currently configured on Exchange boxes. Since Windows 2008 R2 Powershell is not as a rich as in Windows 2012, I had to do some head scratching and googling.

As a result I ended up having the script which connects to every Exchange server and output them in the nice Excel file format like CSV.

I had to overcome one thing though as when I was that values for such important parameters like IPSubnet or  DefaultIPGateway and most importantly  DNSDomainSuffixSearchOrder were outputted into CSV as ugly. "System.String[]". I overcame this by using expression like this @{Name="IPAddress";Expression={$_.IPAddress}} for each important network configuration parameter and in particular for DNSDomainSuffixSearchOrder which was my target.

Another caveat here is that Edge servers are not members of the AD and hence execution of Get-WmiObject against them will fail if we simply run it, so I had to filter them out from the Get-ExchangeServer command by the {$_.ServerRole -ne "Edge"} filter.

As a result I have ended up with a nice script as this one:

Get-ExchangeServer | Where-Object {$_.ServerRole -ne "Edge"} |foreach {Get-WmiObject -Class Win32_NetworkAdapterConfiguration -Filter IPEnabled=TRUE -ComputerName $_.Name} |Select-Object DNSHostName,Description,@{Name="IPAddress";Expression={$_.IPAddress}},@{Name="IPSubnet";Expression={$_.IPSubnet}},@{Name="DefaultIPGateway";Expression={$_.DefaultIPGateway}},@{Name="DNSServerSearchOrder";Expression={$_.DNSServerSearchOrder}},@{Name="DNSDomainSuffixSearchOrder";Expression={$_.DNSDomainSuffixSearchOrder}} |export-csv D:\scripts\Exchange_IP_Config_Reporting.csv

Which provides me with output as below (IP addresses and hostnames are not included for the sake of professional ethics)

This resulted in a happy customer which can make a decision on how DNS settings are to be configured.