powershell

Last time we discovered just how powerful yet SAFE Powershell is with the –WHATIF parameter.  Today we’re going to show you how navigating the Registry is very similar to navigating and working with the filesystem with GET-CHILDITEM and GET-ITEM

So in Powershell we have what are known as “Providers”.  Providers (for lack of better words) “Provide” us with a neutral method to connect to various unrelated systems.

To get a list of Providers I just key in

GET-PSPROVIDER

This will give us a list like this

image

As you can see there are various providers in Powershell.  Some for WebServices Management, File system (C,D) and even certificates .  

So to get a directory in Powershell I normally key in something like

GET-CHILDITEM C:

Here’s the cool part.  Do you see under “Drives” we have two entries ?  HKLM and HKCU ? If I would like a like a Registry keys in HKLM (HKEY-LOCAL-MACHINE) I would just key in

GET-CHILDITEM HKLM:

image

As you can see, we’re looking at a list of registry keys.   As you can ALSO see, Powershell has to work with the same ACL’s as in the real world so if you try to access something YOU’RE NOT EVER SUPPOSED TO TOUCH (like our little friend “SAM” here) it will spit out an error.    But for neatness, we can tell Powershell to suppress those errors too.     Although you can change the overall configuration by messing with your variables,  I like to do it on an as needed basis.  Adding on the parameter –ErrorAction SilentlyContinue allows this to not disturb you temporarily.

GET-CHILDITEM HKLM: –ErrorAction SilentlyContinue

image

If you’d like to set this as a default in your profile or even just even  for all the Cmdlets in a session just set the Variable $ErrorActionPreference=’SilentlyContinue’

Now here’s something you just couldn’t do in DOS.  Change from the File system to the Registry just as if it were a Drive letter!

Key In

SET-LOCATION HKLM:

and then type in

CD SOFTWARE

then execute a GET-CHILDITEM

image

Does this look familiar?

image

You guessed it.  With Powershell you can not only VIEW but Navigate the registry as easily as the filesystem.

Next time we’ll take a glance at creating content in the registry with Powershell

The Power of Shell is in YOU

Sean
The Energized Tech