# Scripts to manage registry entries on Windows devices

The Windows registry is organized into a tree-like structure consisting of nodes called registry keys. These registry keys contain values called registry entries, which are properties of the corresponding registry key. You can customize and configure the system to suit your specific needs by managing registry entries on Windows devices.

While it is possible to modify the registry manually using the built-in Registry Editor tool, it can be time-consuming and error prone. This document focuses on scripts designed to manage registry entries efficiently. Use Hexnode’s [Execute Custom Script](https://www.hexnode.com/mobile-device-management/help/executing-custom-scripts-for-windows/) feature to remotely deploy these scripts to multiple devices in no time.

 Disclaimer: 
The sample scripts provided below are adapted from third-party open-source sites.

 

PowerShell commands to manage registry entries in local machine registry
------------------------------------------------------------------------

### List the registry entries

The easiest way to examine registry entries is to get the name of the property associated with the key. A registry key has a property with the generic name “Property”, which is a list of registry entries in the key. The following command selects the Property attribute and expands the items so that they appear in the list:

Script to list registry entries

Get-Item -Path "Registry\_path" | Select-Object -ExpandProperty Property

   1

2

  Get-Item -Path "Registry\_path" |

Select-Object -ExpandProperty Property

   

 

  

For example, to display the list of entries in *HKEY\_LOCAL\_MACHINE\\SYSTEM\\CurrentControlSet\\Control* use the following script:

Sample script to list registry entries

Get-Item -Path Registry::HKEY\_LOCAL\_MACHINE\\SYSTEM\\CurrentControlSet\\Control | Select-Object -ExpandProperty Property

   1

2

  Get-Item -Path Registry::HKEY\_LOCAL\_MACHINE\\SYSTEM\\CurrentControlSet\\Control |

Select-Object -ExpandProperty Property

   

 

  

![Display a list of all registry entries](https://cdn.hexnode.com/mobile-device-management/help/wp-content/uploads/2023/05/List-registry-entries.png "List registry entries")[](https://cdn.hexnode.com/mobile-device-management/help/wp-content/uploads/2023/05/List-registry-entries.png)

For a more readable representation of the registry entries, you can use the **Get-ItemProperty** command.

Sample script to view registry entries

Get-ItemProperty -Path Registry::HKEY\_LOCAL\_MACHINE\\SYSTEM\\CurrentControlSet\\Control

   1

  Get-ItemProperty -Path Registry::HKEY\_LOCAL\_MACHINE\\SYSTEM\\CurrentControlSet\\Control

   

 

  

![Display the list of registry entries in a more readable form](https://cdn.hexnode.com/mobile-device-management/help/wp-content/uploads/2023/05/List-registry-entries-in-more-readable-form.png "List registry entries in more readable form")[](https://cdn.hexnode.com/mobile-device-management/help/wp-content/uploads/2023/05/List-registry-entries-in-more-readable-form.png)

You can navigate to the *Control* registry container using the **Set-Location** command. And, using the “.” notation for the current location helps list the properties without defining the full path.

Script to set location and list registry entries

Set-Location -Path HKLM:\\SYSTEM\\CurrentControlSet\\Control Get-ItemProperty -Path .

   1

2

  Set-Location -Path HKLM:\\SYSTEM\\CurrentControlSet\\Control

Get-ItemProperty -Path .

   

 

  

### Retrieve a single registry entry

Use the following command to retrieve a specific registry entry *CurrentUser* from the registry *HKLM:\\SYSTEM\\CurrentControlSet\\Control*.

Script to retrieve a specific entry

Get-ItemProperty -Path HKLM:\\SYSTEM\\CurrentControlSet\\Control -Name CurrentUser

   1

  Get-ItemProperty -Path HKLM:\\SYSTEM\\CurrentControlSet\\Control -Name CurrentUser

   

 

  

![Retrieve a specific registry entry from a registry](https:2023/05/Retrieve-a-single-registry-entry.png "Retrieve a single registry entry")[](https:2023/05/Retrieve-a-single-registry-entry.png)

 Note: 
The Get-ItemProperty command provides parameters such as Filter, Include, and Exclude, but they cannot be utilized for filtering by property name. The parameters are associated with registry keys, which refer to paths of items rather than registry entries, which refer to properties of items.

 

### Create a new registry entry

To add a new item named “PowerShellPath” to the Control key, the **New-ItemProperty** command can be used with the key’s path, the entry name, and its corresponding value. In this example, it takes the value of the Windows PowerShell variable $PSHome, which stores the installation directory path for the program.

Script to create a new registry entry

New-ItemProperty -Path HKLM:\\SYSTEM\\CurrentControlSet\\Control -Name PowerShellPath -PropertyType String -Value $PSHome

   1

  New-ItemProperty -Path HKLM:\\SYSTEM\\CurrentControlSet\\Control -Name PowerShellPath -PropertyType String -Value $PSHome

   

 

  

![Create a new registry entry](https:2023/05/Create-a-new-registry-entry.png "Create a new registry entry")[](https:2023/05/Create-a-new-registry-entry.png)

To add a registry entry to multiple locations, you can provide an array of values for the Path parameter. For example:

Sample script to add a registry entry to multiple location

New-ItemProperty -Name PowerShellPath -PropertyType String -Value $PSHome ` -Path HKLM:\\SYSTEM\\CurrentControlSet\\Control, HKLM:\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion

   1

2

  New-ItemProperty -Name PowerShellPath -PropertyType String -Value $PSHome `

 -Path HKLM:\\SYSTEM\\CurrentControlSet\\Control, HKLM:\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion

   

 

  

Use **Force** parameter with any **New-ItemProperty** command to overwrite a pre-existing registry entry value.

To set the PropertyType, it is necessary to use the name of a member from the Microsoft.Win32.RegistryValueKind enumeration presented in the table below:

PropertyType ValueMeaningBinaryBinary dataDWordA number that’s a valid UInt32ExpandStringA string that can contain environment variables that are dynamically expanded.MultiStringA multiline stringStringAny string valueQWord8 bytes of binary data### Rename a registry entry

Use the following command to rename the **PowerShellPath** entry to “PSHome”.

Script to rename registry entry

Rename-ItemProperty -Path HKLM:\\SYSTEM\\CurrentControlSet\\Control -Name PowerShellPath -NewName PSHome -passthru

   1

  Rename-ItemProperty -Path HKLM:\\SYSTEM\\CurrentControlSet\\Control -Name PowerShellPath -NewName PSHome -passthru

   

 

  

### Delete the registry entries

Use the following command to delete **PSHome** registry entry.

Script to delete registry entries

Remove-ItemProperty -Path HKLM:\\SYSTEM\\CurrentControlSet\\Control -Name PSHome

   1

  Remove-ItemProperty -Path HKLM:\\SYSTEM\\CurrentControlSet\\Control -Name PSHome

   

 

  

 Notes:- It is recommended to manually validate the script execution on a system before executing the action in bulk.
- Hexnode will not be responsible for any damage/loss to the system on the behavior of the script.