Author Posts

October 12, 2017 at 10:07 pm

assume $computerarray exists

$resultarray = @()

foreach($computer in $computerarray)
{invoke-command $computer.name -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.

October 12, 2017 at 10:34 pm

$ResultArray = foreach ($Computer in @('xxxx-vm0101','xxxx-vm0102','xxxx-vm0103')) {
    Invoke-Command -ComputerName "$Computer.zurich.xxxx.com" -Credential (Get-SBCredential 'xxxx\yyyy') -ScriptBlock {
        [PSCustomObject][Ordered]@{
            ComputerName = $Using:Computer
            Manufacturer = (Get-WmiObject Win32_ComputerSystem).Manufacturer
            TimeZone     = ([System.TimeZone]::CurrentTimeZone).StandardName
        }
    }
} 

$ResultArray | FT ComputerName,Manufacturer,TimeZone -a