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

10 months, 1 week ago.

  • Author
  • #99250

    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

    Points: 25
    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.

denizli escort samsun escort muğla escort ataşehir escort kuşadası escort