Powershell cript to get list of services accounts

Ali AMG 0 Reputation points
2023-02-03T19:55:48.74+00:00

Hello :)

I am looking for a powershell script to retrieve the list of local service accounts

Thank you

PowerShell
PowerShell
A family of Microsoft task automation and configuration management frameworks consisting of a command-line shell and associated scripting language.
2,100 questions
0 comments No comments
{count} votes

3 answers

Sort by: Most helpful
  1. Rich Matheisen 45,096 Reputation points
    2023-02-03T22:22:13.06+00:00

    Define "service account"! Context is important.

    If all you want is the name of a service and the account under which the service runs, then this will work:

    Get-WmiObject Win32_Service | Select-Object name,startname
    

  2. MotoX80 32,076 Reputation points
    2023-02-03T22:32:15.13+00:00

    Or a summary.

    Get-CimInstance win32_service | Where-Object {$_.StartName} | Select-Object StartName -Unique
    

  3. Ken Burns 0 Reputation points
    2023-02-03T23:50:55.5066667+00:00

    Here is a PowerShell script that retrieves the list of local service accounts on a Windows system:

    Get-WmiObject Win32_UserAccount | Where-Object {$.LocalAccount -eq $True -and $.AccountType -eq "512"} | Select-Object Name

    This script uses the Get-WmiObject cmdlet to retrieve a list of user accounts from the Win32_UserAccount WMI class. The Where-Object cmdlet filters the list to include only local accounts that have an AccountType value of 512, which represents service accounts. The Select-Object cmdlet is then used to display only the Name property of each service account.