Invoke-Command Script block remote variables

Welcome Forums General PowerShell Q&A Invoke-Command Script block remote variables

This topic contains 1 reply, has 2 voices, and was last updated by

 
Participant
6 months, 4 weeks ago.

  • Author
    Posts
  • #99250
    dar

    Participant
    Points: 0
    Rank: Member

    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

    Participant
    Points: 22
    Rank: Member

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

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

The topic ‘Invoke-Command Script block remote variables’ is closed to new replies.