Wednesday, September 21, 2016

PowerShell Module for Managing Registry Remotely

Hi folks,

I have recently had an experience where I needed to change registry on more than one server. And of course after this change I wanted to be sure that the registry change has been successful. Of course this can be done by logging in to each of these servers, but I wanted a simple and nice way of reporting of this registry change.

My investigations led me to this site from where you can download remote registry management PowerShell module. From this page you can download this module in form of a ZIP file. When extracted, you will end up having the PSRemoteRegistry folder which contains all the files necessary for module. You will need to copy the whole folder (not just contents) to %WINDIR%\System32\WindowsPowerShell\v1.0\Modules.

As soon as it the folder has been copied you can launch module in PowerShell session:

Import-Module PSRemoteRegistry

This module includes not only commands for reporting registry keys and their values but also for creating and tweaking keys. For the sake of my work I needed only Get-RegKey command which would talk to all my Exchange servers and retrieve the registry key which I had just created along with its configured values and drop them nicely to a report that can be read in Excel.

Imagine a scenario that you need to migrate IRM from one AD RMS cluster to another. For users to access and process emails sent by the previous RMS cluster you will need to establish redirection of old AD RMS cluster URL to the new one. This is done by tweaking registry and fully described here.

I used good old New-Item and New-ItemProperty commands to create registry keys and properties. After they have been created I executed the following code against my all Exchange 2013 and 2016 servers from EMS:

Get-ExchangeServer -Identity $_.ServerName |where {$_.AdminDisplayVersion -like "Version 15*"} |Get-RegKey -ComputerName $_.Name -Key SOFTWARE\Microsoft\ExchangeServer\v15\IRM -Name LicenseServerRedirection |Get-RegValue |select ComputerName,Key,Value,Data,Type |Export-Csv D:\scripts\RMS\Redirection.csv

It first found my all Exchange 2013/16 servers in AD and then executed Get-Reg key against all of them along with the values that i needed to retrieve. The output was nicely placed to CSV file which I can now easily access and read.

Enjoy!

No comments:

Post a Comment