Problem
You want to view the value of a specific registry key.
Solution
To retrieve the value(s) of a registry key, use the GetItemProperty cmdlet, as shown in Example 181.
Example 181. Retrieving properties of a registry key
PS >SetLocation HKCU: PS >SetLocation \Software\Microsoft\Windows\CurrentVersion\Run PS >GetItemProperty .
PSPath
: Microsoft.PowerShell.Core\Registry::HKEY_CURRENT_U
SER\Software\Microsoft\Windows\CurrentVersion\Run
PSParentPath
: Microsoft.PowerShell.Core\Registry::HKEY_CURRENT_U
SER\Software\Microsoft\Windows\CurrentVersion
PSChildName
: Run
PSDrive
: HKCU
PSProvider
: Microsoft.PowerShell.Core\Registry
FolderShare
: "C:\Program Files\FolderShare\FolderShare.exe" /ba
ckground
TaskSwitchXP
: d:\lee\tools\TaskSwitchXP.exe
ctfmon.exe
: C:\WINDOWS\system32\ctfmon.exe
Ditto
: C:\Program Files\Ditto\Ditto.exe
QuickTime Task
: "C:\Program Files\QuickTime Alternative\qttask.exe
" atboottime
H/PC Connection Agent : "C:\Program Files\Microsoft ActiveSync\wcescomm.exe"
Discussion
In the registry provider, PowerShell treats registry keys as items and key values as properties of those items. To get the properties of an item, use the GetItemProperty cmdlet. The GetItemProperty cmdlet has the standard alias, gp.
Example 181 lists all property values associated with that specific key. To retrieve the value of a specific item, access it as though you would access a property on a .NET object, or anywhere else in PowerShell:
PS >$item = GetItemProperty . PS >$item.TaskSwitchXp d:\lee\tools\TaskSwitchXP.exe
If you want to do this all at once, the command looks like:
PS >$runKey = "HKCU:\Software\Microsoft\Windows\CurrentVersion\Run" PS >(GetItemProperty $runKey).TaskSwitchXp d:\lee\tools\TaskSwitchXP.exe
For more information about the GetItemProperty cmdlet, type GetHelp GetItemProperty. For more information about the registry provider, type GetHelp Registry.