# Step 1: Create a backup folder if it does not exist
$backupFolderPath = "C:\Windows\RegistryBackup"
if (!(Test-Path -Path $backupFolderPath -PathType Container)) {
Write-Host "Creating backup folder: $backupFolderPath"
New-Item -Path $backupFolderPath -ItemType Directory -Force | Out-Null
}
# Step 2: Backup registry for each root key
$rootKeys = @(
"HKCU",
"HKLM",
"HKU",
"HKCR",
"HKCC"
)
foreach ($rootKey in $rootKeys) {
# Define export path for the current root key
$regPath = Join-Path -Path $backupFolderPath -ChildPath "$rootKey.reg"
# Backup the current root key
Write-Host "Exporting $rootKey to $regPath"
reg export "$rootKey" "$regPath" /y
}
# Step 3: List the steps performed
Write-Host "Backup completed successfully!"
Write-Host "Steps performed:"
Write-Host "1. Created backup folder: $backupFolderPath"
foreach ($rootKey in $rootKeys) {
$regPath = Join-Path -Path $backupFolderPath -ChildPath "$rootKey.reg"
Write-Host "2. Exported $rootKey to $regPath"
}
This website uses cookies to enhance your browsing experience, analyze site traffic, and serve better user experiences. By continuing to use this site, you consent to our use of cookies. Learn more in our cookie policy