PowerShell: Windows Registry

By Xah Lee. Date: . Last updated: .

Here's how to use PowerShell to view/edit Windows Registry.

For basic concept of Windows Registry, see Windows: Registry Tutorial

Go to a registry key location

# goto Registry HKEY_CURRENT_USER
cd hkcu:
# goto Registry HKEY_LOCAL_MACHINE
cd hklm:
# goto a key directly
cd hkcu:\Software\Microsoft\Windows\CurrentVersion\Explorer\Wallpapers\

List keys in current location

dir .

List values in current location

Use Get-ItemProperty (alias gp)

gp .
PowerShell show registry values 20210607214557
show registry values by Get-ItemProperty

Set value

Use Set-ItemProperty (alias sp).

example of set a registry value:

# set Microsoft pinyin input system to use dvorak layout
sp -Path "hklm:\SYSTEM\CurrentControlSet\Control\Keyboard Layouts\00000804" -Name "Layout File" -Value "KBDDV.DLL"
# set Microsoft pinyin input system to use qwerty layout
sp -Path "hklm:\SYSTEM\CurrentControlSet\Control\Keyboard Layouts\00000804" -Name "Layout File" -Value "KBDUS.DLL"

# http://xahlee.info/comp/Chinese_input_with_Dvorak.html

Create a new key

mkdir xyz

Remove a key

Use Remove-Item (alias rm).

rm xyz
# remove a key and all its subkeys and values
rm -Recurse xyz
# remove a key and all its subkeys and values
rm HKLM:\SOFTWARE\xyz98479 -Recurse
# remove a key's subkeys and values
rm HKLM:\SOFTWARE\xyz98479\* -Recurse

Create a new value

cd hkcu:\Software\Microsoft\Windows\CurrentVersion\Explorer\Wallpapers\
New-ItemProperty -Path . -Name xyz -Type DWORD -Value 1
PowerShell registry 20210607220324
New-ItemProperty

Clear a value

Clear-ItemProperty -path . -Name BackgroundHistoryPath0

Clear all values of a key

Clear-Item .

Remove a value

Use Remove-ItemProperty (alias rp).

rp -Path hkcu:\Software\Microsoft\Windows\CurrentVersion\Explorer\Wallpapers\ -Name BackgroundHistoryPath1

Rename key

Rename-Item

$path = "HKLM:\SOFTWARE\xyzkey"
Rename-Item -Path $path -NewName xyzkey2

Rename value

Rename-ItemProperty

$path = "HKLM:\SOFTWARE\xyzkey"
Rename-ItemProperty -Path $path -Name xyzVal2 -NewName xyzVal3

Copy key

Copy-Item -Path $path -Destination $dest

Copy value

Copy-ItemProperty -Path $path -Destination $dest -Name $name

Move key

Move-Item -Path $path -Destination $dest

Move value

Move-ItemProperty -Path $path -Destination $dest -Name $name