PowerShell Script to get Exchange Version, Build and Rollup

Friday, May 22, 2009
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 ""
}

29 comments:

  1. How about one line of code :-)

    PS > Get-ExchangeServer | Format-List Name,ServerRole,Edition,ExchangeVersion

    ReplyDelete
  2. Thanks, Shay, but that only gives you the Exchange version number.

    The code above tells you the Exchange version number, build number, which Update Rollup versions are installed and when they were installed. This is the only way I've found to determine which UR is installed.

    ReplyDelete
  3. Thanks for a great script. I didn't notice the RU info. I ran the script on a VM with no RUs applied.

    ReplyDelete
  4. There is a bug in the installed date string.. should be
    $d = $d.substring(4,2) + "/" + $d.substring(6,2) + "/" + $d.substring(0,4)

    (originally there were 2 references to substring(4,2)

    ReplyDelete
  5. Why do I get this error?

    The term 'Get-ExchangeServer' is not recognized as a cmdlet, function, operable
    program, or script file. Verify the term and try again.
    At C:\Get-ExchangeServerVersion.ps1:8 char:33

    ReplyDelete
    Replies
    1. ...also if you get an error trying to run the script, try using the complete Path and File Name, instead of just the File Name

      Delete
  6. Anonymous: Chances are you're running the script from a PowerShell prompt, instead of the Exchange Management Shell. Run the script from EMS and it should work.

    ReplyDelete
  7. Ok. Just one question.. I don't have any Exchange 2007 in my env. Will the 'Microsoft Exchange Server 2007 Management Tools (32-Bit)' work in my Exch 2003 env?

    ReplyDelete
  8. Hmmm. It should, but I haven't tried it. If you do, let me know how it goes.

    ReplyDelete
  9. The script works gr8 but how to get the output in CSV file.

    ReplyDelete
  10. To get the script to output to a txt file just add | out-file -filepath c:\FILENAME.txt

    ReplyDelete
  11. ExchangeVersion returned in not entirely correct. The version returned is "the minimum version of the product that can read the object".

    Check out http://blogs.technet.com/b/scottschnoll/archive/2006/12/31/exchange-2007-platforms-and-product-keys.aspx

    ReplyDelete
  12. To get the correct installed version of Exchange, modify line 18 as follows.
    $txt1 = $MsxServer.Name + " [" + $MsxServer.ServerRole + "] [" + $MsxServer.Edition + "] " + $MsxServer.AdminDisplayVersion #$MsxVersion.ExchangeBuild.toString()

    ReplyDelete
  13. Thanks very much, Tim! I've updated the downloadable script and the code above.

    ReplyDelete
  14. Hi Jeff, I run the script from EMS but I got the following error message;
    The term 'Get-ExchangeServerVersion.ps1' is not recognized as a cmdlet, function, operable program,
    or script file. Verify the term and try again.
    At line:1 char:29

    ReplyDelete
  15. is this blog alive? any hint to Bobby's problem?

    ReplyDelete
  16. This is a common Powershell error if the Powershell environment cannot locate the script your are trying to run. It will also happen if you are not running the script from the Exchange Management Shell.

    Open EMS and move to the folder where the script exists to run it.

    ReplyDelete
  17. Great script, thanks you've saved me hours of coding. I modified the reg key as follows to work on Exchange 2010 SP1:

    HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Installer\UserData\S-1-5-18\Products\AE1D439464EB1B8488741FFA028E291C

    ReplyDelete
  18. Thanks. This is a very handy script which makes things easier.

    ReplyDelete
  19. Thanks for the nice script, his was secure my day ;-)

    ReplyDelete
  20. Thanks I used it for EX2010

    ReplyDelete
  21. for exchange 2010 -
    Get-ExchangeServer | fl name, admindisplayversion

    ReplyDelete
  22. Nice work i really appreciate that .just tell me how to find the platform for installed exchange server 2007.Of course in production environment each and everyone is preferring for 64 bit platform but i want to ensure that through command .Please tell me the command to find the platform for installed exchange server 2007 in production environment.

    ReplyDelete
  23. Created version that works for Exchange 2007, 2010, and 2013
    Posted here: http://blog.jasonsherry.net/2012/12/27/get-exchangever/

    ReplyDelete
  24. Get-ExchangeServer -Identity votreserveur | Format-Table Name, AdminDisplayVersion

    (avec votreserveur comme nom du serveur Exchange voulu)

    ou dans le cas d’un seul serveur Exchange
    Get-ExchangeServer | Format-Table Name, AdminDisplayVersion

    La version 14.0 correspond à Exchange 2010

    La version 14.1 correspond à Exchange 2010 SP1

    ReplyDelete

Thank you for your comment! It is my hope that you find the information here useful. Let others know if this post helped you out, or if you have a comment or further information.