The registry is Windows' configuration database full of hidden values. This episode turns it into a filesystem PowerShell can explore: reading and writing values, creating keys, backups, and safely managing the registry of remote machines.

In episode 18 you managed Active Directory — the organization's identity hub. But every Windows machine also has its own equally important local configuration hub: the registry. If AD is the organization's phone book, the registry is each machine's "personal filing cabinet" — where Windows and applications store settings. The registry is famously mysterious: nested key trees, odd value types like DWord and REG_SZ, and small mistakes can stop an application — even Windows — from booting.
In this episode we pull back that veil in the most elegant way PowerShell provides: treating the registry as a filesystem. In PowerShell, HKLM: isn't just a virtual drive — it's the doorway to the entire registry structure using exactly the same commands as exploring folders.
Since the early episodes you've been familiar with Get-ChildItem for exploring folders. Good news: the registry is a folder. PowerShell provides two registry provider drives:
| Drive | Contents | Analogy |
|---|---|---|
HKLM: | HKEY_LOCAL_MACHINE — machine configuration (global) | The building's archive shelf: all occupants use it |
HKCU: | HKEY_CURRENT_USER — configuration of the logged-in user | Your personal desk drawer |
Check the available drives and start exploring:
Get-PSDrive -PSProvider Registry
Get-ChildItem -Path "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion" |
Select-Object Name, SubKeyCount, ValueCountNote the structure: keys (like folders) and values (like files). One key can contain sub-keys and several values. This is why PowerShell calls it the registry provider — all filesystem operations work, plus dedicated cmdlets for values.
Tip
Exploring the registry is like exploring ordinary folders: use cd HKLM:\SOFTWARE to move, then dir alias Get-ChildItem to see the contents. All the navigation techniques you've mastered for the filesystem apply directly — that's the advantage of PowerShell's provider design.
The main cmdlet for reading values is Get-ItemProperty. The difference from Get-ChildItem: the former shows the values belonging to a key, while the latter shows the sub-keys:
Get-ItemProperty -Path "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion" -Name "ProgramFilesDir"
Get-ItemProperty -Path "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion" -Name "ProgramFilesDir" |
Select-Object -ExpandProperty ProgramFilesDirThe second line uses Select-Object -ExpandProperty to pull out only the value — not the object with metadata. This is a pattern you'll often need when a registry value is used as input to another command.
For a list of sub-keys, use Get-ChildItem:
Get-ChildItem -Path "HKLM:\SOFTWARE" | Select-Object Name
Get-ChildItem -Path "HKCU:\Software" -Recurse -Depth 2 |
Select-Object -First 20 FullNameNote: -Recurse on the HKLM: root without -Depth takes a very long time because the tree is very deep. Limit with -Depth or start from a specific key.
New-Item creates a key; New-ItemProperty creates a value inside it:
New-Item -Path "HKCU:\Software\MyApp" -Force
New-ItemProperty -Path "HKCU:\Software\MyApp" `
-Name "Version" `
-Value "1.0" `
-PropertyType StringThe most common value types:
| PropertyType | Registry Type | Use |
|---|---|---|
String | REG_SZ | Plain text (paths, names) |
ExpandString | REG_EXPAND_SZ | Text with environment variables |
DWord | REG_DWORD | 32-bit numbers (flags, ports) |
QWord | REG_QWORD | 64-bit numbers |
Binary | REG_BINARY | Raw binary data |
Choosing the right -PropertyType matters: applications read this type to decide how to interpret the value. A DWord value created as a String will be misinterpreted.
Set-ItemProperty changes existing values without recreating them:
Set-ItemProperty -Path "HKCU:\Software\MyApp" -Name "Version" -Value "1.1"
Set-ItemProperty -Path "HKCU:\Software\MyApp" -Name "AutoStart" -Value 1 -PropertyType DWordNote the value 1 for DWord — a numeric type, without quotes; this sets the "auto start enabled" flag.
Remove-ItemProperty deletes a value; Remove-Item deletes a key along with its contents:
Remove-ItemProperty -Path "HKCU:\Software\MyApp" -Name "Version"
Remove-Item -Path "HKCU:\Software\MyApp" -Confirm:$trueThe most common real-world pattern: read a value, compare, change if different. Example: check the Windows build version before running a script that depends on a specific version:
$currentBuild = (Get-ItemProperty -Path "HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion" -Name "CurrentBuildNumber").CurrentBuildNumber
if ($currentBuild -ge 22000) {
Write-Output "Windows 11 atau lebih baru: build $currentBuild"
} else {
Write-Output "Windows 10 atau lebih lama: build $currentBuild"
}The golden rule before touching the registry: back up first. PowerShell leverages the classic reg export to save a key snapshot to a .reg file:
$stamp = Get-Date -Format "yyyyMMdd_HHmmss"
$backupFile = "C:\Backup\MyApp_$stamp.reg"
reg export "HKCU\Software\MyApp" $backupFile
Write-Output "Backup tersimpan di $backupFile"If something goes wrong, you just reg import the file to restore the original state. For small keys, also save the value list to CSV as documentation:
Get-ItemProperty -Path "HKCU:\Software\MyApp" |
ConvertTo-Json | Out-File "C:\Backup\MyApp_values.json"To manage another machine's registry, PowerShell Remoting (covered in episode 16) is the way — every target machine must have WinRM enabled:
Invoke-Command -ComputerName "server-01" -ScriptBlock {
Get-ItemProperty -Path "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion" -Name "ProgramFilesDir"
}The script inside -ScriptBlock runs on the target machine, so the HKLM: path refers to that server's registry — not your local machine. This is how you check the configuration of hundreds of servers without logging into each one.
Warning
Almost all applications read the registry only at startup. Changing registry values often doesn't take effect until the application (or Windows) is restarted. Don't be surprised if changes aren't visible immediately — and don't rewrite the same value over and over just because "it didn't change".
The registry is the least forgiving place in Windows. Four habits you should internalize:
reg export is cheaper than restoring a machine that won't boot.try-catch block:try {
Set-ItemProperty -Path "HKCU:\Software\MyApp" `
-Name "Version" -Value "1.2" -ErrorAction Stop
Write-Output "Nilai berhasil diubah"
} catch {
Write-Output "Gagal mengubah registry: $($_.Exception.Message)"
}-ErrorAction Stop turns a non-terminating error into one that throws an exception, so the catch block really works. Without it, the script continues to the next line as if it had succeeded.
Important
Avoid writing directly to third-party application registries. Configurations supported through application settings or Group Policy are far safer and better documented. The registry is a last resort — not the first place to put settings, but the last place after all other options are exhausted.
In this episode 19 you've opened Windows' secret chest: the registry viewed as an explorable filesystem. You understand the two provider drives, HKLM: for machine configuration and HKCU: for user configuration; read values with Get-ItemProperty, keys with Get-ChildItem; write new keys and values with New-Item and New-ItemProperty; change with Set-ItemProperty; delete with Remove-ItemProperty; plus common tasks like backup via reg export, and managing remote machines' registry via Invoke-Command.
Key takeaways:
-PropertyType; applications read this type to interpret values.try-catch and -ErrorAction Stop.Machine configuration is now at your fingertips. But there's one type of configuration update that has the biggest impact and is most often postponed: Windows patching. In the next episode, episode 20, we'll cover Windows Updates & Patching: the PSWindowsUpdate module for update automation, WSUS integration for large organizations, update history with Get-Hotfix, and patch verification and rollback. See you there!