I'm trying to export a registry key on a remote machine using the code:
Foreach ($server in $servers)
{
$backupFolder = $global:backupFolder
$serverName = $server
$backupFile = $global:backupFolder '\' $scmRef "_" $server "_" $userId ".reg"
$registryEntry = "HKLM:\SOFTWARE\South River Technologies\Titan FTP Server\Servers\2\Users\"
Write-Host "Reg" $backupFile $registryEntry
Invoke-Command -ComputerName $server -ScriptBlock {
Write-Host "Creating Backup Folder on"$Using:serverName
New-Item -Path $Using:backupFolder -type directory -Force
Write-Host "Folder creation complete on"$Using:serverName
reg export $Using:registryEntry $Using:backupFile
Write-Host "Registry exported successfully to" $Using:backupFile
}
}
I'm receiving the error message and not sure why
ERROR: Invalid key name. CategoryInfo : NotSpecified: (ERROR: Invalid key name.:String) [], RemoteException FullyQualifiedErrorId : NativeCommandError PSComputerName : FRUSVAFD01
Type "REG EXPORT /?" for usage.
The code above creates the relevant folder correctly but cannot find the key name despite it being there. I've run locally as reg export HKLM:\SOFTWARE\South River Technologies\Titan FTP Server\Servers\2\Users\ C:\Users<username>\desktop\registryentry.reg and it runs correctly.
Any idea why this doesn't work remotely? I'm at my wits end and have wasted most of the day googling.
Thanks in advance
CodePudding user response:
Your code probably needs a cleanup, but i think the issue is the colon in the registry path. Try changing this:
$registryEntry = "HKLM:\SOFTWARE\South River Technologies\Titan FTP Server\Servers\2\Users\"
to this
$registryEntry = "HKLM\SOFTWARE\South River Technologies\Titan FTP Server\Servers\2\Users\"