add invoke-command scriptblock results to array outside

This topic contains 1 reply, has 2 voices, and was last updated by  Sam Boutros 1 week, 3 days ago.

  • Author
  • #81958

    John Curtiss

    assume $computerarray exists

    $resultarray = @()

    foreach($computer in $computerarray)
    {invoke-command $ -scriptblock {
    $result = do-some-stuff
    if ($result = "awesome"){$result2 = do-other-stuff}
    how might I get $results and/or $result2 out of the scriptblock and into $resultarray? I know how to build an array by adding members to psobject rows, i'm really asking about getting content out of the remote session and back into $resultarray.

  • #81961

    Sam Boutros
    $ResultArray = foreach ($Computer in @('xxxx-vm0101','xxxx-vm0102','xxxx-vm0103')) {
        Invoke-Command -ComputerName "$" -Credential (Get-SBCredential 'xxxx\yyyy') -ScriptBlock {
                ComputerName = $Using:Computer
                Manufacturer = (Get-WmiObject Win32_ComputerSystem).Manufacturer
                TimeZone     = ([System.TimeZone]::CurrentTimeZone).StandardName
    $ResultArray | FT ComputerName,Manufacturer,TimeZone -a 

You must be logged in to reply to this topic.