Random thoughts of an Exchange PFE

This blog is my effort to document and share interesting details about Exchange Server as I come across them in field, lab and community.

PowerShell script to edit remote registry

PowerShell script to edit remote registry

  • Comments 2
  • Likes

Did you ever wanted to modify your registry or add a key/value pair to registry? Wished there was a script to help you do that? Even better, wished it can run remotely without PowerShell WinRM listener configured on target server?

I had custom script that would modify certain registry entry but it was inflexible and in my recent rewrite of another script, I wanted more flexibility. So out of necessity, I decided to rewrite my registry script  and made it independent script with lot of flexibility.

Using this script, you can now run it like this:

.\Set-RemoteRegistry.ps1 -Key SYSTEM\CurrentControlSet\services\AudioSrv\Parameters -Name ServiceDllUnloadOnStop -Value 1 -Type DWord

If you want to suppress prompts, you can use –Force parameter like this:

.\Set-RemoteRegistry.ps1 -Key SYSTEM\CurrentControlSet\services\AudioSrv\Parameters -Name ServiceDllUnloadOnStop -Value 0 -Type DWord –Force

This script is also a good example of cmdletbinding and support of whatif. I still think use of Whatif in scripts has its limitations as apprarent in this script (without adding more code to it to work around that limitation).

The script is also a good example of how you can use parameter validation right in the parameter declaration. This way you can avoid if..then code blocks to validate parameter inputs. What a wonderful discovery, I gotta thank PowerShell team for this.

So go ahead, get the script Set-RemoteRegistry.ps1 here and if you find any issues, let me know. Have Fun!

  • Hi,

    Do you have any idea why I would get the following error from this script.  I just dont understand and I am new to POS as well as scripting.

    G:\powershell\Set-RemoteRegistry.ps1 : hklm:\SOFTWARE\Wow6432Node\Microsoft\CCM\ doesn't exist. Exiting.

    At line:1 char:21

    the syntax I am using is

    .\set-remoteregistry  -Key hklm:\SOFTWARE\Wow6432Node\Microsoft\CCM\CcmExec -name -provisioningmode -Value false -type string\

    Im sure Im doing something stupid, but I would appreciate any help you might be able to offer.

  • Susan,

    The erros is because you are using incorrect syntax. You need to use the following syntax:

    .\set-remoteregistry  -Key SOFTWARE\Wow6432Node\Microsoft\CCM\CcmExec -name -provisioningmode -Value false -type string

    HLKM is hive and if you don't spoecify -hive, localmachine is used as default.

Your comment has been posted.   Close
Thank you, your comment requires moderation so it may take a while to appear.   Close
Leave a Comment