Windows services that are configured to start with a specific user

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
Support_38Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

David Johnson, CD, MVPOwnerCommented:
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

0
it_saigeDeveloperCommented:
*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-
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Support_38Author Commented:
good afternoon Sorry for the delay in the response, that's what I needed. Thank you very much.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Powershell

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.