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!
Originally posted at http://blogs.technet.com/bshukla
[…]PowerShell script to edit remote registry « Bhargav's IT Playground[…]…
Thanks for this cdmlet. I downloaded and tried it out and could not get it to work. I finally realized that is was because I was running an x86 PS shell (for compatibility with some older Citrix PS commands). While I can IEX to a 64-bit shell, is there a modification that can be made to allow this to run in a 32-bit PS shell? Thank you very much.
Can you provide more details on failure? It shouldn’t fail on 32-bit shell.
Thanks for the quick reply! There is no error. “-ErrorAction” returns True and the command appears to work. But when I look at regedit on the remote computer, the entry is not there. When I run from x64, same console results but the key is written correctly. Thank you so much for looking into this. Please feel free to email me directly as well.
When I try to run .\Set-RemoteRegistry.ps1 I get the following error The term ‘.\Set-RemoteRegistry.ps1’ is not recognized as the name of a cmdlet, function, script file, or operable program. Check the
spelling of the name, or if a path was included, verify that the path is correct and try again.
Are you running the command from the location where you have saved the script? dot sourcing (./scriptname.ps1) means PS is going to look for the script in the location where you are running the command from.