RSS

用脚本直接查询域内exchange服务器的版本(支持多服务器)

08 Jun

 

通常我是这么查询。但是不知道当前服务器的rollup 版本。(是,verison 编号和rollup 版本一一对应,但是谁会去记呢?)

 

单服务器多角色的查询

多服务器包含群集的查询(上图是没有打补丁的)

如果安装rollup后的多服务器查询。(打过补丁的服务器查询)

请注意运行该脚本的权限问题。因为需要查询注册表,所以需要remote register 服务开启。

脚本如下:

   1: #Get a list of Exchange servers in the Org excluding Edge servers
   2: $MsxServers = Get-ExchangeServer | where {$_.ServerRole -ne "Edge"} | sort Name
   3:  
   4: #Loop through each Exchange server that is found
   5: ForEach ($MsxServer in $MsxServers)
   6: {
   7:  
   8:     #Get Exchange server version
   9:     $MsxVersion = $MsxServer.ExchangeVersion
  10:  
  11:     #Create "header" string for output
  12:     # Servername [Role] [Edition] Version Number
  13:     $txt1 = $MsxServer.Name + " [" + $MsxServer.ServerRole + "] [" + $MsxServer.Edition + "] " + $MsxVersion.ExchangeBuild.toString()
  14:     write-host $txt1
  15:  
  16:     #Connect to the Server's remote registry and enumerate all subkeys listed under "Patches"
  17:     $Srv = $MsxServer.Name
  18:     $key = "SOFTWARE\Microsoft\Windows\CurrentVersion\Installer\UserData\S-1-5-18\Products\461C2B4266EDEF444B864AD6D9E5B613\Patches\"
  19:     $type = [Microsoft.Win32.RegistryHive]::LocalMachine
  20:     $regKey = [Microsoft.Win32.RegistryKey]::OpenRemoteBaseKey($type, $Srv)
  21:     $regKey = $regKey.OpenSubKey($key)
  22:  
  23:     #Loop each of the subkeys (Patches) and gather the Installed date and Displayname of the Exchange 2007 patch
  24:     $ErrorActionPreference = "SilentlyContinue"
  25:     ForEach($sub in $regKey.GetSubKeyNames())
  26:     {
  27:         Write-Host "- " -nonewline
  28:         $SUBkey = $key + $Sub
  29:         $SUBregKey = [Microsoft.Win32.RegistryKey]::OpenRemoteBaseKey($type, $Srv)
  30:         $SUBregKey = $SUBregKey.OpenSubKey($SUBkey)
  31:  
  32:         ForEach($SubX in $SUBRegkey.GetValueNames())
  33:         {
  34:             # Display Installed date and Displayname of the Exchange 2007 patch
  35:             IF ($Subx -eq "Installed")   {
  36:                 $d = $SUBRegkey.GetValue($SubX)
  37:                 $d = $d.substring(4,2) + "/" + $d.substring(4,2) + "/" + $d.substring(0,4)
  38:                 write-Host $d -NoNewLine
  39:             }
  40:             IF ($Subx -eq "DisplayName") {write-Host ": "$SUBRegkey.GetValue($SubX)}
  41:         }
  42:     }
  43:         write-host ""
  44: }

下载版本为

http://cid-f934535afc3723ba.skydrive.live.com/self.aspx/.Public/powershell/Get-ExchangeServerVersion.ps1

Advertisements
 
 

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

 
%d bloggers like this: