Skip to content

Instantly share code, notes, and snippets.

@aadennis
Created July 6, 2017 07:58
Show Gist options
  • Save aadennis/db7ef0c7d3b939c7362658dce2b84314 to your computer and use it in GitHub Desktop.
Save aadennis/db7ef0c7d3b939c7362658dce2b84314 to your computer and use it in GitHub Desktop.
<#
.SYNOPSIS
Given a wildcard representing a service logon ("Log On As" in the Windows services grid),
find all services executed by that logon, ON THE CURRENT SERVER.
.DESCRIPTION
As synopsis, plus to use this across a number of VMs, you will have to call this as a script block
.PARAMETER UserWildcard
Wildcard representing a service logon
.EXAMPLE
Get-ServiceSetForLogonUser "sql"
In this case, sql would match e.g. [NT Service\MSSQL$SQLEXPRESS]
.NOTES
General notes
#>
function Get-ServiceSetForLogonUser ($UserWildcard) {
$wildcard = "*$UserWildcard*"
$wildcard
#Get-WmiObject -Class Win32_Service | Where-Object StartName -Like $wildcard | Format-List *
#Get-WmiObject -Class Win32_Service | Where-Object StartName -Like $wildcard | Format-List PSComputerName, Name, StartName | Out-GridView
Get-WmiObject -Class Win32_Service | Where-Object StartName -Like $wildcard | select PSComputerName, Name, StartName | Out-GridView
}
Get-ServiceSetForLogonUser "sql"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment