I am trying to run gpresults remotely. It works but only on one machine instead of the entire list that is in the txt file.
Here is the code
Text
Function get-test(){
$Computers = get-content C:\Users\AdministratorDocuments\WindowsPowerShell\Scripts\Listlaptops.txt
try{
foreach($CO in $Computers){
get-gpresultantsetofpolicy -Computer $CO -ReportType HTML -path C:\Users\Administrator\Documents\WindowsPowerShell\Scripts\$CO.html
}
}
catch [System.Runtime.InteropServices.COMException]{
Write-Host "The $CO is offline"}
}
As soon as I get rid of "try and catch" it works as expected but you get a ton of RPC errors instead of the message. Do I need to add another foreach cmdlet inside catch?