-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathGet-ServicesWithFilter.ps1
More file actions
41 lines (34 loc) · 1.14 KB
/
Get-ServicesWithFilter.ps1
File metadata and controls
41 lines (34 loc) · 1.14 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
<#
.SYNOPSIS
Shows a list of services that matches the parameter combination. Retrieves three properties and sorts on two of them.
.DESCRIPTION
Function to retrieve a list of services based on defined parameters.
.PARAMETER STATE
The state of the service. AKA the Status.
.PARAMETER STARTMODE
The mode the service is set to on start up. AKA the Startup Type.
.EXAMPLE
PS> .\Get-ServicesWithFilter.ps1 -State Stopped -StartMode Auto
#>
param(
[Parameter()]
[ValidateSet("Stopped","Running")]
[string[]]
$State,
[Parameter()]
[ValidateSet("Auto", "Manual", "Disabled")]
[string[]]
$StartMode
)
If ($State -and $StartMode -eq $null)
{
Get-WmiObject win32_service -Filter "State = '$State'" | Select Name, DisplayName, State, StartMode | Sort State, Name
}
ElseIf ($State -eq $null -and $StartMode)
{
Get-WmiObject win32_service -Filter "StartMode = '$StartMode'" | Select Name, DisplayName, State, StartMode | Sort State, Name
}
ElseIf ($State -and $StartMode)
{
Get-WmiObject win32_service -Filter "State = '$State' AND StartMode = '$StartMode'" | Select Name, DisplayName, State, StartMode | Sort State, Name
}