Hey all,

I am trying to piece together a simple script to run against a list of servers to pull the services running on it and the account that is running it.
This only seems to pull from the local machine that is actually running the script. I am sure I’m missing something obvious here but can’t seem to see it myself


```
$computers = Get-Content -Path C:\temp\Serverlist.txt
foreach($computer in $computers)
{Get-WmiObject win32_service | Where-Object {$_.state -eq "running"} | Select-Object systemname,name,startname,state | Export-Csv c:\temp\ServerServicesLogonAs.csv -NoTypeInformation}

```

3 Spice ups

If you post code, please use the ‘Insert Code’ button. Please and thank you!

codebutton_small.png

In your loop, your only asking for local computer info; you need:

gwmi -ComputerName $computer …

2 Spice ups

Sorry about that. Updated the post

OMG, I am such an idiot…wow I can’t believe I didn’t see that.

Thank you very much. I need more sleep…

That and you need to append the CSV, as it is right now it would overwrite it. Or even better write it to a variable and then export the whole thing.

e.g.

or if you want it individually

$computers = Get-Content "C:\temp\Serverlist.txt"
foreach($computer in $computers){\
    Get-WmiObject win32_service -ComputerName $computer | 
    Where-Object {$_.state -eq "running"} | 
    Select-Object systemname,name,startname,state | 
    Export-Csv "c:\temp\ServerServicesLogonAs_$computer.csv" -NoTypeInformation
}
$computers = Get-Content -Path "C:\temp\Serverlist.txt"

$report = 
foreach($computer in $computers){
    Get-WmiObject win32_service -ComputerName $computer | 
    Where-Object {$_.state -eq "running"} | 
    Select-Object systemname,name,startname,state 
}

$report | export-csv "c:\temp\ServerServicesLogonAs.csv" -NoTypeInformation
2 Spice ups

Thank you Neally!