Powershell - working with the registry

This article has been ported from my old TechBlog as it is still valid and useful.

I’ve been a good boy and taken the Lync leap. The really annoying thing I’ve always found about Lync is that it always starts up, especially when I don’t want it to. I reboot my laptop at home in the evening or at the weekend and the next thing I know is people are trying to contact me because they thing I’m working. Please. Working outside working hours? You don’t know me well enough.
So I set about doing something about it.

I started by tracking down what was forcing the Lync startup. I’m running Windows 7 64-bit and I found it here:

HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Run
"Communicator"=”C:\Program Files (x86)\Microsoft Lync\communicator.exe" /fromrunkey


So I set about nobbling that and replacing it with a Scheduled task that runs every weekday at 9am that starts up Lync.

Guess what? It works.

But this post would be far too simple and boring if that’s all I included in it. So let’s use some Powershell and to make this whole process a lot more complicated. But seriously, this is a great opportunity to demonstrate how to work with the Registry using Powershell and to introduce a script I found to help.

The script I found creates a .reg backup of Registry keys / values. The beauty of this is that you can then easily script and record what you are doing. I found the script here: http://franckrichard.blogspot.co.uk/2010/12/generate-reg-regedit-export-to-file.html

It’s quite clearly not my script, but I’ve used it and it does what it says on the tin. I found that I needed to specify ‘HKEY_LOCAL_MACHINE’ instead of ‘HKLM’, but with that heads-up you should find it easy to use. The script is included at the bottom of this page and can also be downloaded directly here. Don’t forget about your execution policy, although Powershell will prompt you if you have forgotten.