List Service Accounts on Services.

Dear All,

I need your help, I would like to list all Service Accounts used on Services, but we have to ignore the Services that use "LocalSystem - Local Service - Network Service"

I would like to see "Service Name" & "Service Account" for each service in Excel file if is possible.

e.g.

I would like to specify mutiple computers, because I have to gather all service accounts used.


Thanks in advance,
LVL 1
Gonzalo BecerraSharePoint - Technical Lead for Operations & Engineering Team - Superrvising AssociateAsked:
Who is Participating?
 
Chris DentConnect With a Mentor PowerShell DeveloperCommented:
We can either take the value from the file we read, or we can pick on one of the values it returns. This version picks on the returned values, it's simpler :)
Get-Content MyList.txt | ForEach-Object {
  Get-WmiObject Win32_Service -Filter "StartName LIKE 'domain\\%'" -ComputerName $_
} | Select-Object SystemName, Name, StartName, Caption | Export-Csv c:\test.csv -NoTypeInformation

Open in new window

Chris
1
 
Felix LevenSenior System and DatabaseadministratorCommented:
gwmi win32_service | where {($_.startname -ne "LocalSystem") -and ($_.startname -ne "networkservice") } | select name, startname, caption | Export-Csv c:test.csv

0
 
Gonzalo BecerraSharePoint - Technical Lead for Operations & Engineering Team - Superrvising AssociateAuthor Commented:
Thanks,

Just to change something I would like to change the where I would like only include the startname that start with "domain\"

And the last think is how can I specify .txt file to read the servers and execute the same query in all servers?.

Thanks in advance,
0
SMB Security Just Got a Layer Stronger

WatchGuard acquires Percipient Networks to extend protection to the DNS layer, further increasing the value of Total Security Suite.  Learn more about what this means for you and how you can improve your security with WatchGuard today!

 
Gonzalo BecerraSharePoint - Technical Lead for Operations & Engineering Team - Superrvising AssociateAuthor Commented:
I just filter only by the accounts with specific domains:

gwmi win32_service | where {($_.startname -like "domain\*")} | select name, startname, caption | Export-Csv c:test.csv
 

Could you please help me to run in multiple servers? I would like to read .txt file with all servernames.
0
 
Chris DentPowerShell DeveloperCommented:
There are a couple of approaches you can adopt. You can lump all your servers together:
$Servers = Get-Content MyList.txt
Get-WmiObject Win32_Service -Filter "StartName LIKE "domain\\%" -ComputerName $Servers |
  Select-Object Name, StartName, Caption | Export-Csv c:\test.csv -NoTypeInformation

Open in new window

Alternatively, you can manually loop, which is perhaps a bit more fault tolerant:
Get-Content MyList.txt | ForEach-Object {
  Get-WmiObject Win32_Service -Filter "StartName LIKE "domain\\%" -ComputerName $_
} | Select-Object Name, StartName, Caption | Export-Csv c:\test.csv -NoTypeInformation

Open in new window

I moved your Where-Object filter into the Filter parameter in the WMI query, it's a bit more efficient, if you get your head around the syntax :) % is equivalent to *, and we have to escape \ with another \.

Chris
0
 
Gonzalo BecerraSharePoint - Technical Lead for Operations & Engineering Team - Superrvising AssociateAuthor Commented:
Hi Chris,

Thank you for your collaboration, I would like to comment I have the following error when I run the alternative #2.


Error.jpg
0
 
Chris DentPowerShell DeveloperCommented:
Apologies, I thought I fixed that.
Get-Content MyList.txt | ForEach-Object {
  Get-WmiObject Win32_Service -Filter "StartName LIKE 'domain\\%'" -ComputerName $_
} | Select-Object Name, StartName, Caption | Export-Csv c:\test.csv -NoTypeInformation

Open in new window

Chris
0
 
Gonzalo BecerraSharePoint - Technical Lead for Operations & Engineering Team - Superrvising AssociateAuthor Commented:
Cool Chris Thanks a lot...It's working the last think how can I add column with the ServerName? To identify this service is from this server.
0
 
Gonzalo BecerraSharePoint - Technical Lead for Operations & Engineering Team - Superrvising AssociateAuthor Commented:
Excellent, you are the best Chris, Thanks a lot for your help.
0
All Courses

From novice to tech pro — start learning today.