Quick dirty post–Powershell Script to check registry keys on remote servers (check for E2010 fixed ports)


Hi all,

I know Exchange 2010 is almost outdated, but that’s just for my reference and also for an example about how to query registry keys at the same time : this script checks servers for specific registry keys, in this example it checks for the registry keys we used in Exchange 2010 to fix ports, which were done for 2 Exchange components (Store and Address Book), using 2 registry keys – More information about how to fix E2010 ports here.

 

Apologize for the drafty post, but again, it’s just for future reference about how to query registry keys in general…

 

 

############################################## Script Start ##############################################

# HOW TO check registry keys

# In the below example: check for Ports fixed for Client Access ....

#

# WARNING : Script Requires Exchange tools to get list of Exchange if you use Get-ClientAccessServer or Get-ExchangeServer

# NOTE: Script does NOT require EXchange tools if you use a Powershell list you put in a variable like $ExchangeServers = "Server1", "Server2", "Server3"

 

 

#Initializing variable - best practice of developpers and just in case

$MSExch1 = $null

$MSExch2 = $null

$MSExch2type = $null

$ExchangeServers = $null

$Reg = $null

$RegKey = $null

$computer = $null

 

# 3 methods to get Exchange CAS servers :

# - filter on the "ServerRole" property of an entire "ExchangeServer" object - PROS: if you have mix of Exchange 2007/2010 servers, you can add an "AdminDisplayVersion" filter to query only the Exchange version you want to check !

# - just do a "Get-ClientAccessServer" - PROS : simpler ! But in case you have mix of E2010/E2007 servers, you'll check all of these

# - give a list of machines to the $ExchangeServers variable like $ExchangeServers = "Server1", "Server2", "Server3"

 

# $ExchangeServers = get-exchangeserver | ? {$_.ServerRole -like "*ClientAccess*" -and $_.AdminDisplayVersion -like "*14.*"} #$ExchangeServers = Get-ClientAccessServer

# $ExchangeServers = "Server1", "Server2", "Server3"

# $ExchangeServers = Get-ClientAccessServer

 

$ExchangeServers = Get-ClientAccessServer

 

 

# Here is where, for each computer on the list in the $ExchangeServers variable, we query the registry keys

foreach ($computer in $ExchangeServers){

    Write-host "Checking computer $Computer"

  #We check if the computer is reachable - if it is, we continue, if it is not, we print "Computer is down" and move on...

    if (test-connection $computer -quiet -count 1)

    {

   

      #First we open the registry on the remote computer - note the ".NET" notation [Object.Properties]::Function([parameters]) ...

        $Reg = [Microsoft.Win32.RegistryKey]::OpenRemoteBaseKey('LocalMachine', $computer)

      #Second we open or navigate to the key where we know we'll find the registry object to query

        $RegKey= $Reg.OpenSubKey("SYSTEM\\CurrentControlSet\\services\\MSExchangeRPC\\ParametersSystem")

      #Third we query the value and the type (DWORD, REG_SZ or whatever) of the key we want (we pass the key name inside the GetValue function)

        $MSExch1 = $RegKey.GetValue("TCP/IP Port")

        $MSExch1type = $RegKey.GetValueKind("TCP/IP Port")

       

 

      #Then we repeat the above for other registry keys...

        $RegKey = $Reg.OpenSubKey("SYSTEM\\CurrentControlSet\\services\\MSExchangeAB\\Parameters")

        $MSExch2 = $RegKEy.GetValue("RpcTcpPort")

        $MSExch2type = $RegKey.GetValueKind("RpcTcpPort")

       

      #We then just pring the value and valuetype on the console, with some fancy colors (Magenta here)

        Write-Host "MSExchangeIS Port = $MSExch1 / Type = $MSExch1type" -foregroundcolor magenta

        Write-Host "MSExchangeAB Port = $MSExch2 / Type = $MSExch2type" -foregroundcolor magenta

 

    }

    else

    {

        Write-Host "$computer is down" -foregroundcolor RED

    }

}

 

############################################## Script End ##############################################

 

 

 

Have fun !

Cheers,

Sam


Comments (0)

Skip to main content