I am trying to access the array variable outside the invoke command. I tried the below code, where I cannot access the remote array variable from my local session.
$serverlist = @("server1", "server2")
foreach ($server in $serverlist) {
#Write-Host $computer
$vinodh = Invoke-Command -ComputerName $server -ScriptBlock {
$testVar = @("Stack", "over", "flow")
}
}
foreach ($vars in $testVar) {
Write-Host $vars # Unable to get the values as stack,over, flow
}
Actual results: unable to get values.
I expect the output as
stack over flow