Registry 1
In this http://itknowledgeexchange.techtarget.com/powershell/wmi-and-the-registry/ and subsequent posts I looked at using WMI to work with the Registry. As part of a series examining .NET classes that are useful to admins I thought it would be interesting to look at the Registry first.
We start by linking to a registry hive in this case HKLM – the local machine hive
$reg = [Microsoft.Win32.Registry]::LocalMachine
We can then access a subkey.
$key = $reg.OpenSubKey("Software\ITKE PSAdmins")
This is the example key I created in the WMI series so you need to read that to see how I created it.
We can get the number of values
$key.ValueCount
4
Their names
$key.GetValueNames()
String Entry
Expanded String Entry
Dword Entry
Multi-string Entry
and their types
$key.GetValueNames() | foreach {"$_ $($key.GetValueKind($_))"}
String Entry String
Expanded String Entry ExpandString
Dword Entry DWord
Multi-string Entry MultiString
and the actual values
$key.GetValueNames() | foreach {"$_ $($key.GetValue($_))"}
String Entry This is a string
Expanded String Entry C:\Users\Richard\AppData\Local\Temp
Dword Entry 101
Multi-string Entry A B C D