Thursday, July 11, 2013

Get Exchange Roll up script

One of the tasks that I do as Exchange Admin is to patch and upgrade Exchange to the latest version. I cross with the issue about getting the Exchange Roll up version of my 63 Exchange Servers. There are many scripts out there but none satisfied to me.  So I created this power shell script that displays the Roll up version from Exchange 2007 to 2013. You must run it from Exchange Management Shell and of course need to have permissions to execute the 'Get-ExchangeServer' cmdlet. The results are send to console, but you can modify to export the results to a .csv file.

Here is an output of the results:



Well, hope that this script saves you many hours of work like it did it for me.

######################################

## GetExchanegRollUp.ps1 ##
## Creted By: Carlos Ramirez ##

Clear-Host
$ErrorActionPreference = "SilentlyContinue"
$tmpFilePath="c:\temp\E2k.csv"


#Get-ExchangeServer | where {$_.ServerRole -ne "Edge" -and $_.AdminDisplayVersion -like "Version 14*"} |  select-object  @{Name="svrName";Expression={$_.name}},@{Name="exDataPath";Expression={$_.DataPath}} | export-csv $tmpFilePath -notype -force

Get-ExchangeServer | Sort-Object $_.name | select-object  @{Name="svrName";Expression={$_.name}},@{Name="exDataPath";Expression={$_.DataPath}},@{Name="EXVersion";Expression={$_.AdminDisplayVersion}} | export-csv $tmpFilePath -notype -force


$Filecsv = import-csv $tmpFilePath
$BuildPath = $null
foreach($File in $Filecsv)
  {
   $ServerName = $File.svrName
   $MailboxPath = $File.exDataPath
   #echo $ServerName $MailboxPath
   $arrMailboxPath = $MailboxPath.split("\")
   $strBuildPath = $null
   for($i=0;$i-le $arrMailboxPath.length-2;$i++)
      {
  $strBuildPath=$strBuildPath + $arrMailboxPath[$i] + "\"
 } #End for
   
   $fixBuildPath = $strBuildPath.replace(":","$")
   $BuildPath = "\\" + $ServerName + "\" + $fixBuildPath + "Bin\ExSetup.exe"
   
   $ExBuildFile = get-item $BuildPath
   $ExBuildVersion = $ExBuildFile.VersionInfo.ProductVersion
   
   switch($ExBuildVersion)
      { "14.00.0639.021" {write-host $ServerName "-> Microsoft Exchange Server 2010 RTM" -foregroundcolor "green"}
"14.00.0682.001" {write-host $ServerName "-> Update Rollup 1 for Exchange Server 2010" -foregroundcolor "green"}
"14.00.0689.000" {write-host $ServerName "-> Update Rollup 2 for Exchange Server 2010" -foregroundcolor "green"}
"14.00.0694.000" {write-host $ServerName "-> Update Rollup 3 for Exchange Server 2010" -foregroundcolor "green"}
"14.00.0702.001" {write-host $ServerName "-> Update Rollup 4 for Exchange Server 2010" -foregroundcolor "green"}
"14.00.0726.000" {write-host $ServerName "-> Update Rollup 5 for Exchange Server 2010" -foregroundcolor "green"}
"14.01.0218.015" {write-host $ServerName "-> Microsoft Exchange Server 2010 SP1" -foregroundcolor "green"}
"14.01.0255.002" {write-host $ServerName "-> Update Rollup 1 for Exchange Server 2010 SP1" -foregroundcolor "green"}
"14.01.0270.001" {write-host $ServerName "-> Update Rollup 2 for Exchange Server 2010 SP1" -foregroundcolor "green"}
"14.01.0289.003" {write-host $ServerName "-> Update Rollup 3 for Exchange Server 2010 SP1" -foregroundcolor "green"}
"14.01.0289.007" {write-host $ServerName "-> Update Rollup 3-v3 for Exchange Server 2010 SP1" -foregroundcolor "green"}
"14.01.0323.001" {write-host $ServerName "-> Update Rollup 4 for Exchange Server 2010 SP1" -foregroundcolor "green"}
"14.01.0323.006" {write-host $ServerName "-> Update Rollup 4-v2 for Exchange Server 2010 SP1" -foregroundcolor "green"}
"14.01.0339.001" {write-host $ServerName "-> Update Rollup 5 for Exchange Server 2010 SP1" -foregroundcolor "green"}
"14.01.0355.002" {write-host $ServerName "-> Update Rollup 6 for Exchange Server 2010 SP1" -foregroundcolor "green"}
"14.01.0421.000" {write-host $ServerName "-> Update Rollup 7 for Exchange Server 2010 SP1" -foregroundcolor "green"}
"14.01.0421.002" {write-host $ServerName "-> Update Rollup 7-v2 for Exchange Server 2010 SP1" -foregroundcolor "green"}
"14.01.0421.003" {write-host $ServerName "-> Update Rollup 7-v3 for Exchange Server 2010 SP1" -foregroundcolor "green"}
"14.01.0438.000" {write-host $ServerName "-> Update Rollup 8 for Exchange Server 2010 SP1" -foregroundcolor "green"}
    "14.02.0247.005" {write-host $ServerName "-> Microsoft Exchange Server 2010 SP2"  -foregroundcolor "green"}
"14.02.0283.003" {write-host $ServerName "-> Update Rollup 1 for Exchange Server 2010 SP2"   -foregroundcolor "green"}
"14.02.0298.004" {write-host $ServerName "-> Update Rollup 2 for Exchange Server 2010 SP2"  -foregroundcolor "green"}
"14.02.0309.002" {write-host $ServerName "-> Update Rollup 3 for Exchange Server 2010 SP2"  -foregroundcolor "green"}
"14.02.0318.002" {write-host $ServerName "-> Update Rollup 4 for Exchange Server 2010 SP2"  -foregroundcolor "green"}
"14.02.0318.004" {write-host $ServerName "-> Update Rollup 4-v2 for Exchange Server 2010 SP2"  -foregroundcolor "green"}
"14.02.0328.005" {write-host $ServerName "-> Update Rollup 5 for Exchange Server 2010 SP2"  -foregroundcolor "green"}
"14.02.0328.010" {write-host $ServerName "-> Update Rollup 5-v2 for Exchange Server 2010 SP2"  -foregroundcolor "green"}
"14.02.0342.003" {write-host $ServerName "-> Update Rollup 6 for Exchange Server 2010 SP2"  -foregroundcolor "green"}
"14.03.0123.004" {write-host $ServerName "-> Microsoft Exchange Server 2010 SP3" -foregroundcolor "green"}
"14.03.0146.000" {write-host $ServerName "-> Update Rollup 1 for Exchange Server 2010 SP3" -foregroundcolor "green"}

default {write-host $ServerName "-> Undetermined version"  -foregroundcolor "red"}
 } #End switch

   } #End foreach
   

########################################

C.R.

No comments: