I'm using PowerShell and trying to update a list variable that is located outside of my invoke-command command and so far I haven't figure out how to get it to work. The "$USING:vCompliant_target_srvr" value in the body of the command has a red squiggly and the message "The assignment expression is not valid. The input to an assignment operator must be an object that is able to accept assignments..."
$target_servers = "Test1","Test2","Test3"
$vCompliant_target_srvr = ""
foreach($target_server in $target_servers){
$Response = Invoke-Command -ComputerName $target_server -ScriptBlock {
$srvPSV = $PSVersionTable.PSVersion
if(!$srvPSV -lt [Version]'5.1'){
Return @{
# neither of the below works
vCompliant_target_srvr = vCompliant_target_srvr + ,$USING:target_server
vCompliant_target_srvr += vCompliant_target_srvr
}
} else {
write-host "This DOES NOT meet requirements" $USING:target_server
}
}
$Response.GetEnumerator() | %{
Set-Variable $_.Key -Value $_.Value
}
}
$vCompliant_target_srvr
I need to $vCompliant_target_srvr to be global because I want to use it and it's values after the invoke-command runs. I have googled, searched the MS PowerShell site, and searched stack overflow, but I've been unable to figure out how to make it work. Thanks!