What, no HKCR in PowerShell?
This article was originally published here.
Introduction
If you’ve been working with PowerShell for registry access, you’ve probably noticed by now that something is missing.
PowerShell has two registry “drives” defined:
HKLM for HKEY_LOCAL_MACHINE
HKCU for HKEY_CURRENT_USER
The other registry roots are not defined.
The story behind this post
A while ago, a colleague of mine was trying to find and remove some entries from HKEY_CLASSES_ROOT and was having a hard time using RegEdit.
So, I offered my help, while promoting my latest obsession – PowerShell.
Imagine my embarrassment when I found out a minute later that there is no HKCR drive defined in PowerShell.
The solution
Fear not, my friends, for the HKLM and HKCU are merely there for convenience.
You can define by yourself, with a simple command, any registry drive you want.
So, before working on the HKCR drive, we simply define it like so:
New-PSDrive -Name HKCR -PSProvider Registry -Root HKEY_CLASSES_ROOT
New-PSDrive
-NameHKCR -PSProviderRegistry -RootHKEY_CLASSES_ROOT
Now, you have full access to HKEY_CLASSES_ROOT via HKCR.
Have fun. Be responsible.
P.S.
While on this subject, Ever noticed how you can’t use ‘-filter’ with the ‘dir’ command on registry drives?
Well, you can pipe the results through the question mark filter to do the same job, though I’m quite sure there’s some performance penalty. Still, better than the old RegEdit.exe, right?
Here’s an example:
cd
HKLM:\SOFTWARE\ ****
dir
| ?{$_.Name -like“*Int*“}