\n Hi, and welcome to the PowerShell forum! \n\n\nDon’t apologize for being a “noob” or “newbie” or “n00b.” There’s just no need – nobody will think you’re stupid, and the forums are all about asking questions. Just ask! \n\n\nUse a descriptive subject. Don’t say “Need help” or “PowerShell Help”, actually summarize what the problem is. It helps the rest of us keep track of which problem is which. \n\n\nDon’t post massive scripts. We’re all volunteers and we don’t have time to read all that, nor will we copy…\n <\/blockquote>\n<\/aside>\n\n <\/p>","upvoteCount":0,"datePublished":"2021-04-28T17:36:33.000Z","url":"https://community.spiceworks.com/t/need-help-with-powershell/798303/2","author":{"@type":"Person","name":"Neally","url":"https://community.spiceworks.com/u/Neally"}},{"@type":"Answer","text":"
In your loop, your only asking for local computer info; you need:<\/p>\n
gwmi -ComputerName $computer …<\/p>","upvoteCount":2,"datePublished":"2021-04-28T17:39:15.000Z","url":"https://community.spiceworks.com/t/need-help-with-powershell/798303/3","author":{"@type":"Person","name":"gary-m-g","url":"https://community.spiceworks.com/u/gary-m-g"}},{"@type":"Answer","text":"
Sorry about that. Updated the post<\/p>","upvoteCount":0,"datePublished":"2021-04-28T17:40:20.000Z","url":"https://community.spiceworks.com/t/need-help-with-powershell/798303/4","author":{"@type":"Person","name":"chipperchoi","url":"https://community.spiceworks.com/u/chipperchoi"}},{"@type":"Answer","text":"\n\n
<\/div>\n
Gary M G:<\/div>\n
\nIn your loop, your only asking for local computer info; you need:<\/p>\n
gwmi -ComputerName $computer …<\/p>\n<\/blockquote>\n<\/aside>\n
OMG, I am such an idiot…wow I can’t believe I didn’t see that.<\/p>\n
Thank you very much. I need more sleep…<\/p>","upvoteCount":0,"datePublished":"2021-04-28T17:47:58.000Z","url":"https://community.spiceworks.com/t/need-help-with-powershell/798303/5","author":{"@type":"Person","name":"chipperchoi","url":"https://community.spiceworks.com/u/chipperchoi"}},{"@type":"Answer","text":"
Thank you Neally!<\/p>","upvoteCount":0,"datePublished":"2021-04-28T17:58:36.000Z","url":"https://community.spiceworks.com/t/need-help-with-powershell/798303/7","author":{"@type":"Person","name":"chipperchoi","url":"https://community.spiceworks.com/u/chipperchoi"}}]}}
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
Neally
(Neally)
April 28, 2021, 5:36pm
2
If you post code, please use the ‘Insert Code’ button. Please and thank you!
Hi, and welcome to the PowerShell forum!
Don’t apologize for being a “noob” or “newbie” or “n00b.” There’s just no need – nobody will think you’re stupid, and the forums are all about asking questions. Just ask!
Use a descriptive subject. Don’t say “Need help” or “PowerShell Help”, actually summarize what the problem is. It helps the rest of us keep track of which problem is which.
Don’t post massive scripts. We’re all volunteers and we don’t have time to read all that, nor will we copy…
gary-m-g
(Gary M G)
April 28, 2021, 5:39pm
3
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…
Neally
(Neally)
April 28, 2021, 5:48pm
6
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