PowerShell to Get a Registry Value: A Tutorial Walkthrough (2024)

In this article, learn how to use PowerShell to get a registry value and query entries in a registry using a variety of methods.

Let’s get going!

Not a reader? Watch this related video tutorial!

Not seeing the video? Make sure your ad blocker is disabled.

Prerequisites

All examples in this article will be demonstrated using PowerShell 7.1, which at the time this article was published, is the latest version. You can also use Windows PowerShell 5.1 if you choose. You should also have some basic understanding of PowerShell Drives.

Some examples may not work without Administrator privileges.

Getting Registry Keys and Values with Get-ChildItem

One of the easiest ways to find registry keys and values is using the Get-ChildItem cmdlet. This uses PowerShell to get a registry value and more by enumerating items in PowerShell drives. In this case, that PowerShell drive is the HKLM drive found by running Get-PSDrive.

Run the following command in a PowerShell console.

Get-ChildItem -Path 'HKLM:\SOFTWARE\Policies\Microsoft\Windows\WindowsUpdate\'

In the screenshot below, you can see:

  1. The full key path for the WindowsUpdate registry key
  2. The key AU
  3. The list of registry entries in the AU key with corresponding values
PowerShell to Get a Registry Value: A Tutorial Walkthrough (1)

One quick point regarding the above screenshot. You may notice that the output is a little misleading. Normally, PowerShell console output represents properties of an object. Get-ChildItem behaves differently in this case because this object technically has no properties. Extra commands are run in the background to produce display formatting that you see.

Related: How to Check for a Pending Reboot in the Windows Registry

Getting Registry Values with Get-ItemProperty

Continuing with the same registry key as before, let’s use the Get-ItemProperty cmdlet this time and make the output more readable.

Using Get-ItemProperty is best for getting an item property obtaining keys and their values within the registry. Run the command below:

Get-ItemProperty -Path 'HKLM:\SOFTWARE\Policies\Microsoft\Windows\WindowsUpdate\AU'

In the screenshot below, you see a list of the keys and values:

  1. For the registry container AU
  2. PowerShell related properties which all begin with PS
PowerShell to Get a Registry Value: A Tutorial Walkthrough (2)

As an alternative, you can also specify the registry item path to get the same output only slightly faster by using .NET. The below command is using the .NET Registry Class in PowerShell to get a registry value:

Get-ItemProperty -Path Registry::HKEY_LOCAL_MACHINE\SOFTWARE\Policies\Microsoft\Windows\WindowsUpdate\AU

Getting Registry Values with Get-ItemPropertyValue

Now It’s time to look at key values. Using the Get-ItemPropertyValue cmdlet with the same registry container as before, lets look at the value for the key NoAutoUpdate. Run the following PowerShell command:

Get-ItemPropertyValue -Path 'HKLM:\SOFTWARE\Policies\Microsoft\Windows\WindowsUpdate\AU\' -Name NoAutoUpdate

Using Get-ItemPropertyValue, you will get a more succinct output only showing the value and not any of the other information you saw previously.

PowerShell to Get a Registry Value: A Tutorial Walkthrough (3)

Querying the Registry without PS Drives

Throughout this tutorial, you’ve been using PowerShell drives to work with the registry. Doing it this way isn’t the only way; you can also leverage .NET and get registry information via .NET classes too!

For example, perhaps you need to use PowerShell to get a registry value of HKLM:\SOFTWARE\Policies\Microsoft\Windows\WindowsUpdate\AU\ : AutoUpate on a remote computer.

You can do so with .NET by:

  1. Opening the registry connection on the remote computer.
$Registry = [Microsoft.Win32.RegistryKey]::OpenRemoteBaseKey('LocalMachine', $Computername)

2. Opening the specific registry key you’re looking for.

$RegistryKey = $Registry.OpenSubKey("SOFTWARE\Policies\Microsoft\Windows\WindowsUpdate\AU", $true)

3. Using the GetValue() method to query the value of the registry value inside of the registry key.

$RegistryKey.GetValue('AU')

Using .NET rather than PowerShell drives is a bit faster and is an easy way to connect to and use PowerShell to query registry keys and values on remote computers.

Testing Registry Values with Test-Path

Sometimes you just need to validate if a registry value is present. The way you do that is with the Test-Path cmdlet.

Continuing with the WindowsUpdate container, test to see if the AU container is present by running the following PowerShell command:

Test-Path -Path 'HKLM:\SOFTWARE\Policies\Microsoft\Windows\WindowsUpdate\AU'

If the result is True, the key or container exists. But what if you need to test a value or entry exists? Let’s build a custom function for this test:

Function Test-RegistryValue ($regkey, $name) { if (Get-ItemProperty -Path $regkey -Name $name -ErrorAction Ignore) { $true } else { $false } }

Using the custom function, you enter a path and name of the key or container, and the value you are looking for, and the custom function will return True or False (3) as shown in the screenshot below:

PowerShell to Get a Registry Value: A Tutorial Walkthrough (4)

Next Steps

Know that you can use the Get-ChildItem, Get-ItemProperty, and Get-ItemPropertyValue in PowerShell to get a registry value and keys, what else can you do?

If you’d like to learn more about working with the registry with PowerShell, check out the article from Microsoft Docs titled, ‘Working with Registry Keys’. You can also find a great demonstration of setting registry values in the ATA blog post Using Active Setup: How to Set a Registry Value in All Users Hives.

PowerShell to Get a Registry Value: A Tutorial Walkthrough (2024)

FAQs

How to get specific registry key value using PowerShell? ›

Getting a single registry entry

Using Get-ItemProperty , use the Path parameter to specify the name of the key, and the Name parameter to specify the name of the DevicePath entry. This command returns the standard Windows PowerShell properties as well as the DevicePath property.

How to check existence of registry value in PowerShell? ›

You can use Test-Path to check if a registry key exists. Then you can use Set-ItemProperty to create/modify the entry and its value.

How do I query registry value? ›

Reading from the registry is done via the REG QUERY command. This command can be used to retrieve values of any key from within the registry.

Which cmdlet can be issued to retrieve a registry value? ›

The Get-ItemProperty cmdlet gets the properties of the specified items. For example, you can use this cmdlet to get the value of the LastAccessTime property of a file object. You can also use this cmdlet to view registry entries and their values.

How do I export the registry key value? ›

  1. Open the Registry Editor.
  2. Select the appropriate registry key, or My Computer (to export the entire registry)
  3. Select File, Export from the menu bar or right-click on the appropriate registry key and select Export.
  4. Browse to the directory to save the file to and enter a File name.
  5. Click OK to create the export file.

How to read value from registry key? ›

A registry key can contain one value that is not associated with any name. When this unnamed value is displayed in the registry editor, the string "(Default)" appears instead of a name. To retrieve this unnamed value, specify either null or the empty string ("") for valueName .

How to update registry value in PowerShell? ›

You also use Set-ItemProperty to create and change registry values and data. For example, you can add a new registry entry to a key and establish or change its value.

How do I run registry checker? ›

For additional information about the Scanreg. ini file, click the article number below to view the article in the Microsoft Knowledge Base: 183603 How to Customize Registry Checker Tool Settings To start the Windows Registry Checker tool, click Start, click Run, type scanregw.exe in the Open box, and then click OK.

How to check existence of property in PowerShell? ›

Testing for properties

If you need to know if a property exists, you could just check for that property to have a value. But if the value could be $null you can check to see if it exists by checking the psobject. properties for it.

How do I browse the registry in PowerShell? ›

To browse through the registry in PowerShell, we can use the Get-ChildItem command. For example to get all keys from the path HKLM:\Hardware we can use the below command. Or you can set the location and use the dir (get-ChildItem or ls) command to browse the path.

How to check registry from command line? ›

To open Windows registry in the command prompt, press Windows key + R , type cmd, and press Enter . In the Command Prompt, type regedit and press Enter .

What is the registry key value? ›

Registry keys are containers that act like folders, with values or subkeys contained within them. Registry values are similar to files (not containers).

What are the types of registry values in PowerShell? ›

The possible types for a registry value are: string (REG_SZ or REG_MULTI_SZ), expandable string (REG_EXPAND_SZ), integer (REG_DWORD) and binary (REG_BINARY). In order to define a REG_MULTI_SZ value, enter the strings that compose that value, one per-line.

What is registry key in PowerShell? ›

Because registry keys are items on PowerShell drives, working with them is very similar to working with files and folders. One critical difference is that every item on a registry-based PowerShell drive is a container, just like a folder on a file system drive.

What is the set registry key function in PowerShell? ›

The `Set-RegistryKeyValue` function sets the value of a registry key. If the key doesn't exist, it is created first. Uses PowerShell's `New-ItemPropery` to create the value if doesn't exist. Otherwise uses `Set-ItemProperty` to set the value.

How do I find a specific registry key? ›

Solution
  1. Open the Windows Run dialog box by pressing the Windows + R keys (Windows keyboard) or Command + R keys (Mac keyboard).
  2. In the Run dialog box, type Regedit and click OK.
  3. The Registry Editor dialog box will open. ...
  4. Continue expanding folders to locate the Reg Key you need to create, edit, or delete.

How to get value from key value pair in PowerShell? ›

To retrieve a value from a Hashtable using a key in PowerShell, you can use the square bracket notation. For example, if your Hashtable is named $hash and you want to retrieve the value associated with the key “key1”, you can use $hash[“key1”]. This will return the corresponding value.

How do I import a specific registry key? ›

Restore a manual back up
  1. Select Start , type regedit.exe, and then press Enter. ...
  2. In Registry Editor, click File > Import.
  3. In the Import Registry File dialog box, select the location to which you saved the backup copy, select the backup file, and then click Open.

Top Articles
Latest Posts
Article information

Author: Velia Krajcik

Last Updated:

Views: 6245

Rating: 4.3 / 5 (74 voted)

Reviews: 89% of readers found this page helpful

Author information

Name: Velia Krajcik

Birthday: 1996-07-27

Address: 520 Balistreri Mount, South Armand, OR 60528

Phone: +466880739437

Job: Future Retail Associate

Hobby: Polo, Scouting, Worldbuilding, Cosplaying, Photography, Rowing, Nordic skating

Introduction: My name is Velia Krajcik, I am a handsome, clean, lucky, gleaming, magnificent, proud, glorious person who loves writing and wants to share my knowledge and understanding with you.