Tech News Today
  • Hardware
    • Motherboards
    • CPUs
    • Graphic Cards
    • RAM
    • SSDs
    • Computer Cases
    • Monitors
    • Peripherals
    • Power Supply Unit
    • PC Builds
    • Computer Tips
  • Software
  • Operating System
    • Windows
    • Mac
    • Linux
  • Gaming
  • Mobile
  • Console
  • More
    • Internet
    • Networking
    • Security
    • Buyer’s Guide
    • Gadgets
    • Laptops
    • Reviews
    • How To
    • News
Facebook Twitter Instagram
Tech News Today
  • Hardware
    • Motherboards
    • CPUs
    • Graphic Cards
    • RAM
    • SSDs
    • Computer Cases
    • Monitors
    • Peripherals
    • Power Supply Unit
    • PC Builds
    • Computer Tips
  • Software
  • Operating System
    • Windows
    • Mac
    • Linux
  • Gaming
  • Mobile
  • Console
  • More
    • Internet
    • Networking
    • Security
    • Buyer’s Guide
    • Gadgets
    • Laptops
    • Reviews
    • How To
    • News
Tech News Today
Home»Windows»How To Get Registry Value In PowerShell?

How To Get Registry Value In PowerShell?

Grishm DevkotaBy Grishm DevkotaDecember 6, 2022
powershell get registry value

Registry values are the files that contain the properties and settings of the operating system or an installed application. They store individual/global configurations of applications during startup and login. These values come in different formats and can have values in string, hexadecimal or binary.

To get a desired registry key value in PowerShell, users will need to enter syntax called commandlets (cmdlets). These are lightweight commands built in .NET Framework that perform a specific task or form a part of a script in Windows PowerShell.

Table of Contents

  • Methods to Get Registry Key Value in Powershell
    • Test-Path
    • Reg Query
    • Using Get-Item

Methods to Get Registry Key Value in Powershell

The Registry is divided into five main directories called hives. Namely,
  • HKEY_LOCAL_MACHINE(HKLM)
  • HKEY_CURRENT_CONFIG(HKCC)
  • HKEY_CLASSES_ROOT(HKCR)
  • HKEY_USERS(HKU)
  • HKEY_CURRENT_USER(HKCU)

These ‘hives’ contain further sub-directories called Keys which may also contain their own subkeys. These keys are the folders that hold the values and properties of the system/application.

Test-Path

Before we learn to get registry values, it is beneficial to know how to generate and test the path of the registry directory in PowerShell. To do this, you can validate the pathkey using the Test-path commandlet.

This commandlet then returns a ‘True’ value if the key/path exists and returns a ‘False’ value if the path or key does not exist.

  1. Open Run and type powershell to open the PowerShell console
  2. Inside, type the following syntax and press Enter. replace the <registry hive> and <registry path> with their respective entries
    Test-Path <registry hive>:\<registry path>
    eg:Test-Path HKCU:\Software\Microsoft\Windows\CurrentVersion\Run
    test path registry
  3. If the directory folder or path has a blank space between their name, keep the name inside double quotes (“”)
    Test-Path <registry hive>:\"<registry path>"
  4. Now, to test if the value or the registry entry exists in the key, you can use the script provided below.
    Here, the -Path $regkey and -Name $name are to be replaced with their respective values.
Function Test-RegistryValue ($regkey, $name) {
     if (Get-ItemProperty -Path $regkey -Name $name -ErrorAction Ignore) {
         $true
     } else {
         $false
     }
 }

Example,

Function Test-RegistryValue ($regkey, $name) {
     if (Get-ItemProperty -Path HKCU:\Software\Microsoft\Windows\CurrentVersion\Run -Name Chromium -ErrorAction Ignore) {
         $true
     } else {
         $false
     }
 }

Reg Query

The Reg Query cmdlet returns a list of keys or subkey contents. This cmdlet shows the contents that are under the next level or tier of the directory. This cmdlet is useful as it shows all the content inside the specified registry path or directory. 

In this example, the query will display the registry entries that are under the “Run” sub key.

  1. Open Run and type powershell to open the PowerShell console
  2. Inside, type the following commandlets and press Enter
    Reg Query “<registry hive>\<registry pathname>”
    eg:  Reg Query “HKCU\Software\Microsoft\Windows\CurrentVersion\Run”
    Powershell Reg Query

Using Get-Item

The method to get the desired registry key value in PowerShell is by using the Get-Item cmdlets. This retrieves information from directories specified by the user in PowerShell. There are mainly two methods to get the key value from the Get-Item cmdlet.

By using these cmdlets, users can get the desired registry key value in PowerShell.

Get-ItemPropertyValue

Another method to retrieve desired registry value is by using the Get-ItemPropertyValue cmdlet. This cmdlet gets the values or properties of the specified items after executing it.

The syntax to get the registry value:

  1. Open PowerShell and enter the following command
    Get-ItemPropertyValue -Path <registry hive>:\<registry key path>
    eg: Get-ItemPropertyValue -Path HKCU:\Software\Microsoft\Windows\CurrentVersion\Run -Name Chromium
    get item property value
  2. You can additionally set the following parameters after entering the registry key path
ParametersFunction
-Name <String[]>Gets the property of the specified value inside a key 
-Include <String[]>Specifies string array that will be included during operation. Parameter works only if the cmdlet includes the content of the item
-Exclude <String[]>Specifies string array that will be excluded during operation

After entering the syntax, press the Enter key and then the specified registry key contents will be displayed on PowerShell.

Get-ChildItem

Another method to obtain the required registry value in PowerShell is by using the Get-ChildItem cmdlet. This cmdlet enumerates and then displays all the listed items from the specified directory. The cmdlet however, does not return anything if a directory is empty. 

The following syntax is used to retrieve key value from Get-ChildItem cmdlet:

  1. Get-ChildItem -Path <registry hive>:\<registry key path>
    eg: Get-ChildItem -Path HKCU:\Software\Microsoft\Windows\CurrentVersion
    get child item
  2. To execute the cmdlet with parameters, write them in the following manner
    eg: Get-ChildItem -Path HKCU:\Software\Microsoft\Windows\CurrentVersion -Name -Exclude C*
    childitem exclude filter
    The cmdlet excludes all the key and subkeys under the HKCU:\Software\Microsoft\Windows\CurrentVersion path that start with the letter C
  3. You can set the following additional parameters after entering the registry key path
ParameterFunctions
-Include <string[]*>Includes keys and objects specified in the parameter
[eg: -Include *.txt]
-Exclude <string[]*>Excludes keys and objects specified in the parameter
[eg: -Exclude C*]
-Depth <uint32>Defines the number of subkeys the cmdlet can go through. Integer values can range from 0 to 4,294,967,295
[eg: -Depth 3]
-NameLists the subkeys inside the specified key
-HiddenLists only the hidden items inside the specified key. Shows hidden items with the inclusion of -Force parameter

Using this cmdlet instead of Get-ItemPropertyValue gives you a more readable output of the contents inside the registry key . 

how to
Grishm Devkota
  • LinkedIn

Grishm holds a computer science degree and is currently employed as a Tech writer at TechNewsToday. He specializes in topics related to Windows OS, iOS and PC hardware. You can contact him at grishm@technewstoday.com

Related Posts

how to delete win backup files

How to Delete Backup Files on Windows

January 29, 2023
how to reset password on hp laptop

How to Reset Password on HP Laptop

January 29, 2023
Reset BIOS password

4 Ways to Reset BIOS Password

January 28, 2023
how to make windows 11 look like windows 10

How to Make Windows 11 Look Like Windows 10

January 25, 2023
how to find hidden folder in laptop

How to Find Hidden Folder in Laptop

January 24, 2023
mouse not showing in chrome

Mouse Not Showing in Chrome? Here’s How to Fix It

January 25, 2023
Add A Comment

Leave A Reply Cancel Reply

Latest Posts
how long does a cmos battery last

How Long Does a CMOS Battery Last

January 25, 2023
thunderbolt vs usb c

Thunderbolt Vs USB C: What’s the Difference

January 25, 2023
how to find hidden folder in laptop

How to Find Hidden Folder in Laptop

January 24, 2023
You may also like
how-to-connect-headphones-to-tv

5 Ways to Connect Headphones to TV

January 29, 2023
connect-airpods-to-samsung-tv

How to Connect AirPods to Samsung TV? (Step-by-Step Guide)

January 29, 2023
AIO Pump Not Working

AIO Pump Not Working? Here’s How to Fix It

January 29, 2023
Recommended
Cookie Clicker Garden Guide

Cookie Clicker Garden Guide to Unlocking Every Seed

September 26, 2021
monitor no signal

Computer Turns On But Monitor Says No Signal (9 Ways To Fix)

November 10, 2022
Facebook Twitter Pinterest
  • Home
  • About Us
  • Our Team
  • Editorial Guidelines
  • Privacy Policy
  • Affiliate Disclosure
© 2023 TechNewsToday.

Type above and press Enter to search. Press Esc to cancel.