Created
November 8, 2017 05:08
-
-
Save midnightfreddie/64a837edc3d0a51b112449814ad5e115 to your computer and use it in GitHub Desktop.
Export remote registry in the same fashion as RegEdit's export function. In reply to https://www.reddit.com/r/PowerShell/comments/7bht8c/exporting_registries/
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function Export-Registry { | |
Param ( | |
$ComputerName = "iis", | |
$Key = "hklm\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall", | |
$LocalPath = "." | |
) | |
$DateText = (Get-Date -Format s) -replace ':', '-' | |
$FileName = "$DateText-$ComputerName.reg" | |
$RemoteScript = { | |
Param ( | |
[String]$Key, | |
[String]$FileName | |
) | |
& reg.exe export "$Key" "$env:TEMP\$FileName" | Out-Null | |
Write-Output $env:TEMP | |
} | |
$RemotePath = Invoke-Command -ComputerName $ComputerName -ScriptBlock $RemoteScript -ArgumentList @($Key, $FileName) | |
Copy-Item "$( $RemotePath -replace '^(\w):', "\\$ComputerName\`$1`$" )\$FileName" "$LocalPath\$FileName" | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment