SOLVED

Return computer names from foreach loop

Brass Contributor

Hello I am looking for a way to list the results from each computer in my computers.txt file when running the script below. When I run it now it just returns the results from each computer but does not list the names of each computer when returning the results. Is there something I can add to the script to list each computer name in the results? Any help is appreciated!

 

$computers = get-content C:\Scripts\Bitlocker\computers.txt
foreach ($computer in $computers) {
invoke-command -computername $computer -scriptblock {gpresult /v /scope computer} | findstr BitLocker
}
2 Replies
best response confirmed by charlie4872 (Brass Contributor)
Solution

@charlie4872 

Hi,

As I see you are showing the result in the console, why don't you simply and before the invoke-command line add the following like

Write-host "I am checking computer $($Computer)" 

@farismalaeb Thanks for the reply that did the trick!

1 best response

Accepted Solutions
best response confirmed by charlie4872 (Brass Contributor)
Solution

@charlie4872 

Hi,

As I see you are showing the result in the console, why don't you simply and before the invoke-command line add the following like

Write-host "I am checking computer $($Computer)" 

View solution in original post