Converting the Windows Script Host RegRead Method

Definition: Returns the value of a key or value-name from the registry.

RegRead

The Windows Script Host methods for working with the registry are generally straightforward. If there’s an exception to that rule, however, it’s this: retrieving all the values in a specified registry key. It’s not particularly hard to read all the values in a registry key, but it’s not particularly intuitive, either.

That’s definitely not the case with Windows PowerShell. Want to read all the values in the registry key HKCU:\Software\Microsoft\Internet Explorer\Main? Then just point the Get-ItemProperty cmdlet towards that registry path (note that, for the sake of readability, we then piped the returned data to the Format-List cmdlet):

Get-ItemProperty "HKCU:\Software\Microsoft\Internet Explorer\Main" | Format-List

That should give you output similar to this:

NoUpdateCheck                      : 1
NoJITSetup                         : 1
Disable Script Debugger            : no
Show_ChannelBand                   : No
Anchor Underline                   : yes
Cache_Update_Frequency             : Once_Per_Session
Display Inline Images              : yes
Do404Search                        : {1, 0, 0, 0}
Local Page                         : C:\WINDOWS\system32\blank.htm

Etc.

By the way, notice that we enclosed the registry path in double quote marks. We had to do that because of the blank space in the path (the blank space between Internet and Explorer).

If you just want to return a single value you can use standard dot notation: call Get-ItemProperty (enclosing this call in parentheses) then follow the closing parentheses with a dot and the name of the property. In the following example, we enclosed the value name in double quotes because – that’s right, because of the blank space in the name.

Here’s a command which returns the name of your Internet Explorer home page:

(Get-ItemProperty "HKCU:\Software\Microsoft\Internet Explorer\Main")."Start Page"

And here’s the kind of output you should get back:

https://www.microsoft.com/technet/scriptcenter

Hey, what a coincidence: that’s our home page, too!

Of course, you can also pipe all the registry values to Select-Object and then let Select-Object grab only the values of interest:

Get-ItemProperty "HKCU:\Software\Microsoft\Internet Explorer\Main" | Select-Object "Start Page", "Search Page", "Local Page" | Format-List

And here’s the kind of output you can expect to see:

Start Page  : https://www.microsoft.com/technet/scriptcenter
Search Page : https://www.microsoft.com/isapi/redir.dll?prd=ie&ar=iesearch
Local Page  : C:\WINDOWS\system32\blank.htm

See conversions of other Windows Script Host methods and properties.
Return to the VBScript to Windows PowerShell home page