powershellserveragentpowershell-remotingremoting

Powershell script to extract a list of servers/computers from a .txt file and then display status and then export to CSV?


I have a list of 140 servers in a txt file and need to check status of Crowdstrike on each of them and then export to CSV. Would the below be correct?

$Computers = Get-Content -Path C:\temp\servers.txt

ForEach($Computer in $Computers){
Get-Service -Displayname "Crowdstrike Falcon Sensor Service"| select Status | export-csv c:\temp\results.csv -NoTypeInformation -Append 
}

I have tried the above and resulted in error.


Solution

  • As Santiago points out, you're not using your iteration variable, $Computer, in the loop body, so all Get-Service calls are made locally.


    Note:


    [1] If either endpoint was a non-.NET component, this form of remoting relied on DCOM - see the docs.