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\

or

# example of go to a registry location
cd hkcu:
cd HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\Wallpapers\

List keys in current location

Get-ChildItem .

List values in current location

use Get-Item or Get-ItemProperty

Get-Item .
PowerShell show registry values 2021-06-07
show registry values by Get-Item
Get-ItemProperty .
screenshot 20210607214557 r2HBx
show registry values by Get-ItemProperty

Set value

Use Set-ItemProperty

# example of set a registry value

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

# set Microsoft pinyin input system to use qwerty layout
Set-ItemProperty -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

mkdir xyz

Remove a key

Remove-Item xyz
# remove a key and all its subkeys and values
Remove-Item -Recurse xyz
# remove a key and all its subkeys and values
Remove-Item -Path HKLM:\SOFTWARE\xyz98479 -Recurse
# remove a key's subkeys and values
Remove-Item -Path 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

Remove-ItemProperty -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

PowerShell

How-to

Advanced

Script Examples