Friday, May 22, 2009

PowerShell Script to get Exchange Version, Build and Rollup

It's not easy to tell which version and build is installed on Exchange 2007.

I wanted to find a way to display the Exchange version, build number and which Update Rollup is installed on all servers in the organization. I found the perfect script written by Paul Faherty to do just that. I modified the script slightly to work better in Exchange 2003 / 2007 mixed environments.

Download Get-ExchangeServerVersion.ps1 here: Get-ExchangeServerVersion.zip

When you run it from the Exchange Management Shell prompt you will see output similar to the following screen:

The output displays the server name, Exchange roles installed, version (Standard or Enterprise), version number, and the Update Rollups installed and their installation dates.

For you code monkeys, here's the Powershell code:
#Get-ExchangeServerPlus.ps1
#v1.2, 09/17/2010
#Written By Paul Flaherty, blogs.flaphead.com
#Modified by Jeff Guillet, http://www.expta.com/


#Get a list of Exchange servers in the Org excluding Edge servers
$MsxServers = Get-ExchangeServer | where {$_.ServerRole -ne "Edge"} | sort Name
#Loop through each Exchange server that is found
ForEach ($MsxServer in $MsxServers)
{
 #Get Exchange server version
 $MsxVersion = $MsxServer.ExchangeVersion
 #Create "header" string for output
 # Servername [Role] [Edition] Version Number
 $txt1 = $MsxServer.Name + " [" + $MsxServer.ServerRole + "] [" + $MsxServer.Edition + "] " + $MsxServer.AdminDisplayVersion #$MsxVersion.ExchangeBuild.toString()
 write-host $txt1
 #Connect to the Server's remote registry and enumerate all subkeys listed under "Patches"
 $Srv = $MsxServer.Name
 $key = "SOFTWARE\Microsoft\Windows\CurrentVersion\Installer\UserData\S-1-5-18\Products\461C2B4266EDEF444B864AD6D9E5B613\Patches\"
 $type = [Microsoft.Win32.RegistryHive]::LocalMachine
 $regKey = [Microsoft.Win32.RegistryKey]::OpenRemoteBaseKey($type, $Srv)
 $regKey = $regKey.OpenSubKey($key)
 #Loop each of the subkeys (Patches) and gather the Installed date and Displayname of the Exchange 2007 patch
 $ErrorActionPreference = "SilentlyContinue"
 ForEach($sub in $regKey.GetSubKeyNames())
 {
  Write-Host "- " -nonewline
  $SUBkey = $key + $Sub
  $SUBregKey = [Microsoft.Win32.RegistryKey]::OpenRemoteBaseKey($type, $Srv)
  $SUBregKey = $SUBregKey.OpenSubKey($SUBkey)
  ForEach($SubX in $SUBRegkey.GetValueNames())
  {
   # Display Installed date and Displayname of the Exchange 2007 patch
   IF ($Subx -eq "Installed")   {
    $d = $SUBRegkey.GetValue($SubX)
    $d = $d.substring(4,2) + "/" + $d.substring(6,2) + "/" + $d.substring(0,4)
    write-Host $d -NoNewLine
   }
   IF ($Subx -eq "DisplayName") {write-Host ": "$SUBRegkey.GetValue($SubX)}
  }
 }
  write-host ""
}
12:50 PM