Author Posts

April 19, 2018 at 2:04 pm

I am not sure if my terms are correct so please bear with me.
I want to run a simple invoke-command to a remote machine. Then use get the data from that same variable.
I need a type of global variable or something that stores the data and can be retrieved from the remote machine.
Quick example:
invoke-Command -Computer $Servers -Scriptblock { $test = "Test" }
Echo $test

Is there global variables for remote commands? Or do I need to pass parameters somehow?

April 19, 2018 at 2:24 pm

You can save the results of Invoke-Command to a variable. i.e.:

$results = Invoke-Command -Computer $Servers -Scriptblock {$ENV:Computername}