HOWTO · PowerShell
How to Manage Registries Using Windows PowerShell
Learn how to back up a specific Windows Registry key, import a reviewed .REG file, and inspect registry values with PowerShell.
On this page
Use PowerShell to inspect registry data and call Windows tools to export or import keys. Registry edits can affect Windows or an application, so identify the exact key and review any file before applying it. Back up the specific key you plan to change; an export is useful protection, but it does not guarantee recovery in every situation.
Understand the Windows Registry and PowerShell Paths
The Windows Registry stores configuration for Windows, hardware, applications, and user preferences. It is organized into keys and values. A key resembles a folder, while its values hold named data. HKLM is a common abbreviation for HKEY_LOCAL_MACHINE, which contains machine-wide settings; other hives hold data for users or the current user.
PowerShell exposes registry keys through its Registry provider. For example, HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion is a provider path, while Registry::HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion is an explicit provider-qualified path. These paths are inputs to PowerShell cmdlets such as Get-ItemProperty. By contrast, reg export and reg import are commands supplied by Windows, not PowerShell cmdlets. Use the path form expected by each command.
Back Up a Registry Key with reg export
Run reg export from PowerShell to save a key and its subkeys in a .REG file. Specify the key to export, a destination file, and /y if an existing destination may be overwritten. Create the destination directory first and use an account with permission to read the key. For example, reg.exe export 'HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion' "$env:TEMP\CurrentVersion.reg" /y targets one application key rather than all of HKLM. This Windows command depends on reg.exe and the target registry key, so it must be run on Windows; a non-Windows PowerShell environment cannot verify the export.
The destination is a file under the current user’s temporary directory. Choose a protected location for a backup you intend to keep, and confirm that the command reports success and that the file exists before making changes. A successful export records the selected key; it does not back up the whole hive or guarantee that every system state can be restored.
Restore a .REG File with reg import
reg import applies the keys and values described by a .REG file to the registry. Inspect the file’s contents and target paths before running it, and consider whether the current account has the required permissions. Importing a previous export is not a guaranteed rollback: the file may not represent later changes, and importing it can overwrite values or add data.
For example, after replacing the path with the reviewed file you intend to apply, run reg.exe import 'C:\RegBack\CurrentVersion.reg' in PowerShell. This Windows operation depends on reg.exe and the file; it may require an elevated PowerShell session depending on the target key. Do not treat opening a .REG file or accepting a prompt as proof that its contents are appropriate.
Read Registry Values with Get-ItemProperty
Use Get-ItemProperty with a registry provider path to read the values stored on a key. On Windows, for example, Get-ItemProperty -Path 'Registry::HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion' | Select-Object -Property ProgramFilesDir reads a standard key and selects one named value. This command needs the Windows Registry provider and an existing key, so a non-Windows PowerShell environment cannot verify it. The following self-contained example demonstrates selecting a named property from a PowerShell object; it does not access the registry.
Run this example:
$key = [pscustomobject]@{ ProgramFilesDir = 'C:\Program Files' }
Write-Output $key.ProgramFilesDir
C:\Program Files
Get-ItemProperty returns a PowerShell object whose properties include the registry values; Select-Object limits the displayed properties in the Windows command above. Exact values depend on the Windows installation, so inspect the result on the machine you are administering. Get-Item instead returns the registry key object itself, which is useful when you need to inspect the key rather than retrieve its value properties.
Verify Changes and Work Safely
Before an operation, check that the path names the intended hive and key. For an export, verify the destination file and command result. For an import, review the file and then query the affected key with Get-ItemProperty to confirm the values you meant to apply. Compare only the relevant properties; a command returning an object does not establish that unrelated settings are unchanged.
Use the least-privileged account that can perform the task, and elevate only when Windows permissions require it. Keep backup files access-controlled because registry exports can contain configuration or user-specific data. If a change causes a problem, use an appropriate recovery plan for the affected system; do not assume that importing one .REG file will restore every prior state.