Invoke-Command Script block remote variables

This topic contains 1 reply, has 2 voices, and was last updated by  Jeremy Corbello 1 month ago.

  • Author
    Posts
  • #99250

    dar
    Participant

    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?

  • #99253

    Jeremy Corbello
    Participant

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

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

You must be logged in to reply to this topic.