SOLVED

Return computer names from foreach loop

%3CLINGO-SUB%20id%3D%22lingo-sub-1837957%22%20slang%3D%22en-US%22%3EReturn%20computer%20names%20from%20foreach%20loop%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1837957%22%20slang%3D%22en-US%22%3E%3CP%3EHello%20I%20am%20looking%20for%20a%20way%20to%20list%20the%20results%20from%20each%20computer%20in%20my%20computers.txt%20file%20when%20running%20the%20script%20below.%20When%20I%20run%20it%20now%20it%20just%20returns%20the%20results%20from%20each%20computer%20but%20does%20not%20list%20the%20names%20of%20each%20computer%20when%20returning%20the%20results.%20Is%20there%20something%20I%20can%20add%20to%20the%20script%20to%20list%20each%20computer%20name%20in%20the%20results%3F%20Any%20help%20is%20appreciated!%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CPRE%20class%3D%22lia-code-sample%20language-applescript%22%3E%3CCODE%3E%24computers%20%3D%20get-content%20C%3A%5CScripts%5CBitlocker%5Ccomputers.txt%0Aforeach%20(%24computer%20in%20%24computers)%20%7B%0Ainvoke-command%20-computername%20%24computer%20-scriptblock%20%7Bgpresult%20%2Fv%20%2Fscope%20computer%7D%20%7C%20findstr%20BitLocker%0A%7D%3C%2FCODE%3E%3C%2FPRE%3E%3C%2FLINGO-BODY%3E%3CLINGO-LABS%20id%3D%22lingo-labs-1837957%22%20slang%3D%22en-US%22%3E%3CLINGO-LABEL%3EPowerShell%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3EWindows%20PowerShell%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1838576%22%20slang%3D%22en-US%22%3ERe%3A%20Return%20computer%20names%20from%20foreach%20loop%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1838576%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F531473%22%20target%3D%22_blank%22%3E%40charlie4872%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%3CP%3EHi%2C%3C%2FP%3E%3CP%3EAs%20I%20see%20you%20are%20showing%20the%20result%20in%20the%20console%2C%20why%20don't%20you%20simply%20and%20before%20the%20invoke-command%20line%20add%20the%20following%20like%3C%2FP%3E%3CPRE%20class%3D%22lia-code-sample%20language-powershell%22%3E%3CCODE%3EWrite-host%20%22I%20am%20checking%20computer%20%24(%24Computer)%22%20%3C%2FCODE%3E%3C%2FPRE%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1839080%22%20slang%3D%22en-US%22%3ERe%3A%20Return%20computer%20names%20from%20foreach%20loop%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1839080%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F790105%22%20target%3D%22_blank%22%3E%40farismalaeb%3C%2FA%3E%26nbsp%3BThanks%20for%20the%20reply%20that%20did%20the%20trick!%3C%2FP%3E%3C%2FLINGO-BODY%3E
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 (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!