-
Notifications
You must be signed in to change notification settings - Fork 0
/
GetServicePropertyFunction.ps1
47 lines (46 loc) · 1.25 KB
/
GetServicePropertyFunction.ps1
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
42
43
44
45
46
47
function Get-ServiceProperty
{
<#
.SYNOPSIS
Returns a list of specified properties about a service.
.DESCRIPTION
Uses Win32_Service to gather information about service properties.
.PARAMETER Name
Specifies the name of the service
.PARAMETER Property
Specifies the property or properties to return, accepts wildcards.
.EXAMPLE
Get-ServiceProperty -Name RemoteRegistry
.EXAMPLE
Get-ServiceProperty -Name RemoteRegistry -Property *
.EXAMPLE
Get-ServiceProperty -Name RemoteRegistry -Property StartName,DelayedAutoStart,PathName
.Example
Get-Service RemoteRegistry | Get-ServiceProperty
#>
[CmdletBinding()]
param(
[Parameter(Mandatory = $true, ValueFromPipeline = $true, ValueFromPipelineByPropertyName = $true)]
[string]$Name,
[string[]]$Property)
begin
{
if ($null -eq $Property)
{
$Property = 'ExitCode', 'Name', 'ProcessID', 'StartMode', 'State', 'Status'
}
elseif ('*' -ne $Property)
{
$Property += 'ExitCode', 'Name', 'ProcessID', 'StartMode', 'State', 'Status'
}
}
process
{
$filter = "Name = '$Name'"
$return = Get-CimInstance -Class Win32_Service -Filter $filter | Select-Object $Property
}
end
{
$return
}
}