I’ve been trying to solve another problem for weeks. If I’m already in a remote pssession after the command Enter-pssession. How can I save the variable’s value after I Exit-pssession?
$session = New-PSSession -ComputerName <RemoteServer>
Enter-PSSession -Session $session
$remote_var = '3333'
Exit-pssession
$remote_var = ?
I know the way
$var = Invoke-Command -ComputerName <RemoteServer> -ScriptBlock { '3333' }
But this method does not suit me, because we are talking about that I am already constantly in a remote session