PowerShell Registry: Read and Write Registry Keys

PowerShell Registry: Read and Write Registry Keys

PowerShell Tips Editor 4 min read
PowerShell Registry: Read and Write Registry Keys

Deploying software settings, enforcing security policies, or reading application configuration across a fleet of PCs all come back to the Windows Registry — and PowerShell treats it like a file system. PowerShell registry access uses the same Get-Item, Get-ItemProperty, Set-ItemProperty, and New-Item cmdlets you already know from file system work. The registry is just another PSDrive. This post covers reading, writing, creating, and deleting keys and values with working examples for the most common admin tasks.

Navigate the Registry as a Drive

PowerShell maps the registry hives to PSDrives. HKLM: maps to HKEY_LOCAL_MACHINE and HKCU: maps to HKEY_CURRENT_USER. You can use Set-Location to navigate and Get-ChildItem to list subkeys, just like a directory.

# List subkeys under HKLM\SOFTWARE
Get-ChildItem -Path "HKLM:\SOFTWARE" | Select-Object -First 10

# Navigate like a filesystem
Set-Location "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion"
Get-ChildItem

Read a Registry Value

Use Get-ItemProperty to read values from a registry key. The key path is the “folder” and each value name is a “property” on that object.

# Read a specific value
Get-ItemProperty -Path "HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion" `
    -Name "ProductName"
ProductName  : Windows 11 Pro
PSPath       : Microsoft.PowerShell.Core\Registry::HKEY_LOCAL_MACHINE\...
PSParentPath : Microsoft.PowerShell.Core\Registry::HKEY_LOCAL_MACHINE\...
PSChildName  : CurrentVersion
PSDrive      : HKLM
PSProvider   : Microsoft.PowerShell.Core\Registry
# Get just the value (not the full object)
(Get-ItemProperty -Path "HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion" -Name "ProductName").ProductName

Write or Update a Registry Value

Set-ItemProperty creates or updates a registry value. The key must already exist. Specify -Type to match the required registry data type — String for REG_SZ, DWord for REG_DWORD, ExpandString for REG_EXPAND_SZ.

# Write a string value (REG_SZ)
Set-ItemProperty -Path "HKCU:\Software\MyApp" `
    -Name "Theme" -Value "Dark" -Type String

# Write a DWORD value (REG_DWORD)
Set-ItemProperty -Path "HKCU:\Software\MyApp" `
    -Name "MaxConnections" -Value 10 -Type DWord

Create a New Registry Key

Creating a new registry key uses New-Item, just as you would create a directory. Use -Force to avoid errors if the key already exists — safe for idempotent deployment scripts.

# Create a new key
New-Item -Path "HKCU:\Software\MyCompany\MyApp" -Force

# Create key and immediately set a value
$keyPath = "HKLM:\SOFTWARE\MyCompany\Config"
New-Item -Path $keyPath -Force
Set-ItemProperty -Path $keyPath -Name "InstallPath" -Value "C:\Program Files\MyApp" -Type String
Set-ItemProperty -Path $keyPath -Name "Version" -Value 3 -Type DWord

Delete Registry Keys and Values

Delete individual values with Remove-ItemProperty. Delete entire keys (and all values within them) with Remove-Item -Recurse. Always confirm the path before running deletion commands — there is no registry recycle bin.

# Delete a single registry value
Remove-ItemProperty -Path "HKCU:\Software\MyApp" -Name "OldSetting"

# Delete an entire registry key and all its subkeys
Remove-Item -Path "HKCU:\Software\MyApp" -Recurse -Confirm:$false

Remote Registry with Invoke-Command

Direct remote registry access requires the Remote Registry service, which is often disabled. A more reliable approach is to use Invoke-Command over WinRM to run the registry commands on the remote machine.

$targetComputer = "server01"
$regValue = Invoke-Command -ComputerName $targetComputer -ScriptBlock {
    (Get-ItemProperty -Path "HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion" `
        -Name "ProductName").ProductName
}
Write-Output "$targetComputer OS: $regValue"
# Deploy a setting to multiple computers
$computers = @("ws01", "ws02", "ws03")
Invoke-Command -ComputerName $computers -ScriptBlock {
    $keyPath = "HKLM:\SOFTWARE\MyCompany\Config"
    New-Item -Path $keyPath -Force | Out-Null
    Set-ItemProperty -Path $keyPath -Name "AutoUpdate" -Value 1 -Type DWord
    Write-Output "$env:COMPUTERNAME: Setting applied"
}

Common Errors and Fixes

  • HKLM requires admin rights to write: Writing to HKLM: requires an elevated PowerShell session. HKCU: can be written without elevation since it belongs to the current user. If your script targets HKLM on remote machines via Invoke-Command, ensure the credential used has local administrator rights on the target.
  • REG_DWORD vs REG_SZ type must match: Setting an integer value as -Type String stores it as text, which breaks applications that read it as a number. Always verify the expected data type in the application’s documentation or check an existing installation with Get-ItemProperty. Common types: String (REG_SZ), DWord (REG_DWORD), QWord (REG_QWORD), Binary (REG_BINARY), MultiString (REG_MULTI_SZ), ExpandString (REG_EXPAND_SZ).

Related Cmdlets / See Also

Wrapping Up

The registry-as-filesystem model in PowerShell makes configuration deployment straightforward — the same cmdlets you use for files work here too. As a next step, combine the Invoke-Command remote pattern above with a computer list from Active Directory to deploy a registry setting fleet-wide in a single script run.

Send-Item -To