I'm trying to format my output to look like so
PSComputerName Value
-------------- ------
Computer1 Restricted
Computer2 Unrestricted
Computer3 Unrestricted
This is my code the variable $computers points to Get-Content of a file with computer names that I will be connecting to remotely
$test = Invoke-Command -ComputerName $computers -ScriptBlock {
$policy3 = Get-ExecutionPolicy
Write-Output $policy3
}
write $test
The output
PSComputerName RunspaceId Value
-------------- ---------- -----
Computer1 7e4ebfbe-62d3-4035-9d5a... Restricted
Computer2 2ecd6932-1ed4-4f57-b9e9... Unrestricted
Computer3 73a119de-5d6d-4525-9958... Restricted
I've been trying to get rid of the RunSpaceId by echoing the invoke-command and doing a foreach of the computer names, I only did PSComputerNames to test if it would work.
write $test % {$_.PSComputerName }
I know that Invoke-Command has a foreach function built in it but I don't know how to use to my advantage in this situation. What is the best way to achieve my desired output?