Windows services that are configured to start with a specific user

Support_38
Support_38 used Ask the Experts™
on
Good Morning

I need to discover in a server group all the Windows services that are configured to start with a specific user.

Would anyone have any scripts to help with this job?

Thank you very much
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Top Expert 2016
Commented:
function Get-ServiceAccount
{
  <#
      .SYNOPSIS
      Gets Services with User Accounts
      .DESCRIPTION
      This Gets Accounts that use a Username for Login
      .EXAMPLE
      Get-ServiceAccount
      Gets Service Accounts on Local Computer
     
      .EXAMPLE
      Get-ServiceAccount -computerName server01,server02,server03
      Gets Service Accounts from Multiple Computers that have a defined username and password
  #>
  [CmdletBinding()]
  Param(
    [Parameter(Mandatory = $False,Position = 1)]
    [string]$computerName = 'localhost'
  )
  Get-WmiObject -Class win32_service |
  Select-Object -Property name, startname|
  Export-Csv -Path file.csv -NoTypeInformation
  $services = Get-WmiObject  -Class win32_service -ComputerName $computerName 
  foreach ($service in $services) 
  {
    if ( ($service.startname -ne 'LocalSystem') -and ($service.startname -notlike 'NT Authority\LocalService')  -and ($service.StartName -notlike 'NT AUTHORITY\NetworkService') `
    -and ($service.Startname -notlike '') ) 
    {
     
      Write-Host ('Service: {0} uses Login: {1}' -f $service.Name, $service.StartName)
    }
  }
}

Open in new window

Commented:
*NO POINTS*

With a small modification, we can make David's script search for specific username-
function Get-ServiceAccount
{
    <#
        .SYNOPSIS
        Gets Services with User Accounts
        .DESCRIPTION
        This Gets Accounts that use a Username for Login
        .EXAMPLE
        Get-ServiceAccount
        Gets Service Accounts on Local Computer

        .EXAMPLE
        Get-ServiceAccount -computerName server01,server02,server03
        Gets Service Accounts from Multiple Computers that have a defined username and password

        .EXAMPLE
        Get-ServiceAccount -usernameName LocalSystem
        Gets Service Accounts that use a specific user
    #>
    [CmdletBinding()]
    Param(
        [Parameter(Mandatory = $False,Position = 1)]
        [string]$computerName = 'localhost',
        [Parameter(Mandatory = $False,Position = 2)]
        [string]$userName = ''
    )

    if (![string]::IsNullOrWhiteSpace($userName))
    {
        $services = Get-WmiObject -Class win32_service -ComputerName $computerName | Where-Object {$_.StartName -like $userName}
    }
    else
    {
        $services = Get-WmiObject -Class win32_service -ComputerName $computerName | Where-Object {$_.StartName -ne 'LocalSystem' `
            -and $_.StartName -notLike 'NT Authority\LocalService' -and $_.StartName -notLike 'NT AUTHORITY\NetworkService' -and $_.StartName -notLike ''}
    }

    foreach ($service in $services)
    {
        Write-Host ('Service: {0} uses Login: {1}' -f $service.Name, $service.StartName)
    }
}

Open in new window


-saige-

Author

Commented:
good afternoon Sorry for the delay in the response, that's what I needed. Thank you very much.

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial