New PowerShell 5 Feature Provids Better Registry Support
Summary: Ed Wilson, Microsoft Scripting Guy, talks about a new feature in Windows PowerShell 5.0 that providers better registry support.
Microsoft Scripting Guy, Ed Wilson, is here. The Windows PowerShell registry drive has always been somewhat of a love-hate relationship with me. I mean, it makes such great sense to be able to work with the registry via Windows PowerShell, but still, it always seemed a bit backwards.
I know lots of people who stuck with using the .NET registry classes, the old RegRead and RegWrite methods from the VBScript days, or even WMI to work with the registry. Clearly, there was something more needed, and clearly it was not all an “old habits die hard” kind of a thing.
Me? I decided I would stick with the registry provider. Especially, when we got remoting in Windows PowerShell 2.0, and I could work with the registry on remote systems (of course, with some limitations).
There are still some limitations, and I guess that is partially the nature of the registry. (For example, my Hkey_Current_User is not your Hkey_Current_User—and sometimes it is not even my own Hkey_Current_User…but I digress.) However, we have made a nice change that will clean up stuff in Windows PowerShell 5.0.
Finding the value of a registry property
In older versions of Windows PowerShell, if I wanted to find the value of a registry property, I had to monkey around a bit to get it. For example, in the following image, I would like to see the value of my Windows PowerShell execution policy (yes, I know I can use a cmdlet, but I am using this as an example):
So, my registry key name is: HKEY_CURRENT_USER\SOFTWARE\Microsoft\PowerShell\1\ShellIds\Microsoft.PowerShell
…and I want to see the value of the ExecutionPolicy property.
In the old days, I would use Get-ItemProperty and Tab expansion to navigate to the Microsoft.PowerShell key. Then the following default would display:
If I want to get the actual value (so that I can use it to make decisions in a script, for example), I have to use dotted notation, as shown here:
But in Windows PowerShell 5.0, I can use the Get-ItemPropertyValue cmdlet, specify the name of the specific property I want to see, and I will get back the actual value without the necessity of accessing the property on the returned object. This is shown here:
That is all there is to using Windows PowerShell 5.0 to navigate the registry. Join me tomorrow when I will talk about more cool Windows PowerShell stuff.
I invite you to follow me on Twitter and Facebook. If you have any questions, send email to me at email@example.com, or post your questions on the Official Scripting Guys Forum. See you tomorrow. Until then, peace.
Ed Wilson, Microsoft Scripting Guy