Skip to content

Instantly share code, notes, and snippets.

@midnightfreddie
Created November 8, 2017 05:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save midnightfreddie/64a837edc3d0a51b112449814ad5e115 to your computer and use it in GitHub Desktop.
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/
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