1

I am trying to pass a variable to a file name but when the script finishes the file name is blank on the remote machine.

$serv = Read-host 'SERVER NAME'
$Session = New-PSSession -computername $serv 
Invoke-Command -session $session -ScriptBlock {
    reg export HKLM\SYSTEM\CurrentControlSet\services\LanmanServer\Shares C:\Users\admin\Desktop\$Serv.reg
}

Thanks for the help

Santiago Squarzon
  • 41,465
  • 5
  • 14
  • 37
junior
  • 11
  • 1
  • 1
    The easiest way would be to reference the variable with `$using:` => `$using:Serv`. The remote session can't see your local variable, – Santiago Squarzon Feb 11 '22 at 01:23

0 Answers0