Configure Registry Keys

SOTI MobiControl
Windows

The Windows registry is a critical part of the operating system, storing vital system and application settings. For IT administrators, modifying registry keys can be a powerful method to customize and configure Windows devices. However, managing registry keys across multiple devices manually can be complex and time-consuming. With the Configure Registry Keys script in SOTI MobiControl, administrators can automate the process of modifying and managing registry settings remotely. This script streamlines the task of registry configuration, ensuring consistency and efficiency across your fleet of Windows devices while reducing the potential for errors.

Important:
  • It is recommended to test the script on a local/ test machine for its purpose and effects. 
  • SOTI MobiControl will not be responsible for any damage/loss to the data/setup based on the behavior of the script.

Read the value of a registry

1 # Define the registry key path and value name
2 $key = 'HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion'
3 $valueName = 'ProductName'
4 try {
5 $windowsVersion = (Get-ItemProperty -Path $key -Name $valueName -ErrorAction Stop).$valueName
6 Write-Output "${valueName}: $windowsVersion"
7 }
8 catch {
9 Write-Error "Failed to read the ${valueName}: $($_.Exception.Message)"
10 }

List the registry entries.

1 # Replace registry path e.g. Registry::HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control
2 Get-Item -Path Registry::HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control |
3 Select-Object -ExpandProperty Property

List the registry entries with more readable representation of the registry entries

1 # Replace registry path e.g. Registry::HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control
2 Get-ItemProperty -Path Registry::HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control

List the registry entries using the Set-Location command

1 # Replace registry path e.g. HKLM:\SYSTEM\CurrentControlSet\Control
2 Set-Location -Path HKLM:\SYSTEM\CurrentControlSet\Control
3 Get-ItemProperty -Path .

Retrieve a single registry entry.

1 # Replace registry path e.g. HKLM:\SYSTEM\CurrentControlSet\Control
2 Get-ItemProperty -Path HKLM:\SYSTEM\CurrentControlSet\Control -Name CurrentUser

Create a new registry entry.

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

Create a registry entry to multiple locations

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

Rename a registry entry

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

Delete the registry entries.

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

List all subkeys in local machine registry

1 Get-ChildItem -Path HKLM:\ | Select-Object Name

Create a subkey inside the local machine registry.

1 # Replace <subkey> with the desired registry subkey and <name_of_the_new_key> with the name of the key to be created
2 New-Item -Path HKLM:\<subkey>\<name_of_the_new_key>

Delete a subkey from the local machine registry

1 Remove-Item -Path HKLM:\<subkey>\<key_to_be_deleted>

Delete all keys under a specific key

1 Remove-Item -Path HKLM:\<subkey>\<keyname>\* -Recurse

Add a new subkey to the local machine registry

1 reg add <keyname> [{/v value | /ve}] [/t datatype] [/s separator] [/d data] /f

Delete a subkey from the local machine registry

1 reg delete <keyname> [{/v value | /ve | /va}] /f

Export subkeys, entries & values of the local machine into a file

1 reg export <keyname> <file> [/y]

Import file content to local machine registry

1 reg import <file>

Save a copy of registry subkeys, entries & values in a file

1 reg save <keyname> <file> [/y]

Restore subkeys & entries back to the local machine registry

1 reg restore <keyname> <file>

Was this helpful?

Need more help?
Ask Community