代码参考至:http://www.bhargavs.com/。
1 ############################################################################# 2 # Get-ExchangeUpdateRollups.ps1 3 # Gets the Exchange Server 2007, Exchange 2010 and Exchange 2013 Update Rollups 4 # installed writes output to CSV file in same folder where script is called from 5 # 6 # Exchange 2013 CU Build Numbers - http://social.technet.microsoft.com/wiki/contents/articles/15776.exchange-server-2013-and-cumulative-updates-cus-build-numbers.aspx 7 # Exchange Server Update Rollups and Build Numbers - http://social.technet.microsoft.com/wiki/contents/articles/240.exchange-server-and-update-rollups-build-numbers.aspx 8 # 9 # This script won‘t report RUs for Exchange Server 2013 since it uses Cummulative Updates (CU). 10 # More details on Exchange Team Blog: Servicing Exchange 2013 11 # http://blogs.technet.com/b/exchange/archive/2013/02/08/servicing-exchange-2013.aspx 12 # 13 # Created by 14 # Bhargav Shukla 15 # http://www.bhargavs.com 16 # 17 # DISCLAIMER 18 # ========== 19 # THIS CODE IS MADE AVAILABLE AS IS, WITHOUT WARRANTY OF ANY KIND. THE ENTIRE 20 # RISK OF THE USE OR THE RESULTS FROM THE USE OF THIS CODE REMAINS WITH THE USER. 21 ############################################################################# 22 23 # Store header in variable 24 $headerLine = 25 @" 26 Exchange 2013 CU Build Numbers - http://social.technet.microsoft.com/wiki/contents/articles/15776.exchange-server-2013-and-cumulative-updates-cus-build-numbers.aspx 27 Exchange Server Update Rollups and Build Numbers - http://social.technet.microsoft.com/wiki/contents/articles/240.exchange-server-and-update-rollups-build-numbers.aspx 28 29 Server Name,Rollup Update Description,Installed Date,ExSetup File Version 30 "@ 31 32 # Write header to file 33 $headerLine | Out-File .\results.csv -Encoding ASCII -Append 34 35 function getRU([string]$Server) 36 { 37 # Set server to connect to 38 $Server = $Server.ToUpper() 39 40 # Check if server is running Exchange 2007, Exchange 2010 or Exchange 2013 41 42 $ExchVer = (Get-ExchangeServer $Server | ForEach {$_.AdminDisplayVersion}) 43 44 # Set appropriate base path to read Registry 45 # Exit function if server is not running Exchange 2007, Exchange 2010 or Exchange 2013 46 if ($ExchVer -match "Version 15") 47 { 48 $REG_KEY = "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Installer\\UserData\\S-1-5-18\\Products\\AE1D439464EB1B8488741FFA028E291C\\Patches" 49 $Reg_ExSetup = "SOFTWARE\\Microsoft\\ExchangeServer\\v15\\Setup" 50 } 51 elseif ($ExchVer -match "Version 14") 52 { 53 $REG_KEY = "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Installer\\UserData\\S-1-5-18\\Products\\AE1D439464EB1B8488741FFA028E291C\\Patches" 54 $Reg_ExSetup = "SOFTWARE\\Microsoft\\ExchangeServer\\v14\\Setup" 55 } 56 elseif ($ExchVer -match "Version 8") 57 { 58 $REG_KEY = "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Installer\\UserData\\S-1-5-18\\Products\\461C2B4266EDEF444B864AD6D9E5B613\\Patches" 59 $Reg_ExSetup = "SOFTWARE\\Microsoft\\Exchange\\Setup" 60 } 61 else 62 { 63 return 64 } 65 66 # Read Rollup Update information from servers 67 # Set Registry constants 68 $VALUE1 = "DisplayName" 69 $VALUE2 = "Installed" 70 $VALUE3 = "MsiInstallPath" 71 72 # Open remote registry 73 $reg = [Microsoft.Win32.RegistryKey]::OpenRemoteBaseKey(‘LocalMachine‘, $Server) 74 75 # Set regKey for MsiInstallPath 76 $regKey= $reg.OpenSubKey($REG_ExSetup) 77 78 # Get Install Path from Registry and replace : with $ 79 $installPath = ($regkey.getvalue($VALUE3) | foreach {$_ -replace (":","`$")}) 80 81 # Set ExSetup.exe path 82 $binFile = "Bin\ExSetup.exe" 83 84 # Get ExSetup.exe file version 85 $exSetupVer = ((Get-Command "\\$Server\$installPath$binFile").FileVersionInfo | ForEach {$_.FileVersion}) 86 87 # Create an array of patch subkeys 88 $regKey= $reg.OpenSubKey($REG_KEY).GetSubKeyNames() | ForEach {"$Reg_Key\\$_"} 89 90 # Walk through patch subkeys and store Rollup Update Description and Installed Date in array variables 91 $dispName = [array] ($regkey | %{$reg.OpenSubKey($_).getvalue($VALUE1)}) 92 $instDate = [array] ($regkey | %{$reg.OpenSubKey($_).getvalue($VALUE2)}) 93 94 # Loop Through array variables and output to a file 95 $countmembers = 0 96 97 if ($regkey -ne $null) 98 { 99 while ($countmembers -lt $dispName.Count) 100 { 101 $server+","+$dispName[$countmembers]+","+$instDate[$countmembers].substring(0,4)+"/"+$instDate[$countmembers].substring(4,2)+"/"+$instDate[$countmembers].substring(6,2)+","+$exsetupver | Out-File .\results.csv -Encoding ASCII -Append 102 $countmembers++ 103 } 104 } 105 else 106 { 107 $server+",No Rollup Updates are installed,,"+$exsetupver | Out-File .\results.csv -Encoding ASCII -Append 108 } 109 } 110 111 # Get Exchange 2007/2010 servers and write Rollup Updates to results file 112 $Servers = (Get-ExchangeServer -Identity WENDY* | Where-Object {($_.AdminDisplayVersion -match "Version 8" -OR $_.AdminDisplayVersion -match "Version 14" -OR $_.AdminDisplayVersion -match "Version 15") -AND $_.ServerRole -ne "ProvisionedServer" -and $_.ServerRole -ne "Edge"} | ForEach {$_.Name}) 113 $Servers | ForEach {getRU $_} 114 Write-Output "Results are stored in $(Get-Location)\results.csv"
时间: 2024-11-13 08:22:21