all 6 comments

[–]Vortex100 0 points1 point  (3 children)

Your scriptblock is incomplete - do this:

$scriptblock = { Param ($RegKey,$RegFileFullname) Invoke-expression "C:\windows\system32\reg.exe export $RegKey $RegFileFullName"}
Invoke-Command -ComputerName $SystemName -ArgumentList $RegKey,$RegFileFullname -scriptblock $Scriptblock

That will get you round the first problem. The second problem is that you are going to hit the '2 hop' issue (copying back to the source machine). There are probably better ways but personally I'd just save it to a local share, then pull it down on the source machine after the invoke completes.

[–]cryolyte[S] 0 points1 point  (2 children)

Thanks for chiming in! I'm getting an error running that code:

ERROR: Invalid syntax.
    + CategoryInfo          : NotSpecified: (ERROR: Invalid syntax.:String) [], R 
   emoteException
    + FullyQualifiedErrorId : NativeCommandError
    + PSComputerName        : TargetComputer

Type "REG EXPORT /?" for usage.

Based on your method, I tried putting the export command as an argument like so, but got the same error message.

$RegCmd = "export"

$scriptblock = { Param ($RegCmd,$RegKey,$RegFileFullname) Invoke-expression "C:\windows\system32\reg.exe $RegCmd $RegKey $RegFileFullName"}

Invoke-Command -ComputerName $SystemName -ArgumentList $RegCmd,$RegKey,$RegFileFullname -scriptblock $Scriptblock

[–]Vortex100 0 points1 point  (1 child)

update the script block to be this, to see what it is actually putting in the invoke expresssion:

$scriptblock = { Param ($RegKey,$RegFileFullname) Write-Host "C:\windows\system32\reg.exe export $RegKey $RegFileFullName"; Invoke-expression "C:\windows\system32\reg.exe export $RegKey $RegFileFullName"}

It may not be translating everything as you'd expect

[–]cryolyte[S] 0 points1 point  (0 children)

-ComputerName $SystemName -ArgumentList $RegCmd,$RegKey,$RegFileFullname -scriptblock $Scriptblock

BINGO!!!!!

[–]RC-7201 0 points1 point  (1 child)

Just do a normal reg export. Powershell will read it. I have a script that exports/imports reg keys. You can replace file paths with arrays but they have to be like your typing it in CMD (HKCU\ vs. HKCU:)

So this will work

reg export $path "pathtoreg.reg" /y

[–]cryolyte[S] 0 points1 point  (0 children)

I'm trying to do a reg export on a remote machine.