internal/functions/get-servicelist.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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
<#
.SYNOPSIS
Get service list from HashTable
 
.DESCRIPTION
Extract the services from the list of entries in the HashTable
 
.PARAMETER All
Switch to instruct the cmdlet to return all services
 
.PARAMETER Aos
Switch to instruct the cmdlet to return AOS
 
.PARAMETER ManagementReporter
Switch to instruct the cmdlet to return ManagementReporter
 
.PARAMETER DIXF
Switch to instruct the cmdlet to return DIXF
 
.EXAMPLE
Get-ServiceList -All
 
This will return all services that the cmdlet knows about.
 
.NOTES
Author: Mötz Jensen (@Splaxi)
 
#>

Function Get-ServiceList {
    [CmdletBinding(DefaultParameterSetName = 'Default')]
    param (
        [Parameter(Mandatory = $false, ParameterSetName = 'Default', Position = 1 )]
        [switch] $All = [switch]::Present,

        [Parameter(Mandatory = $false, ParameterSetName = 'Specific', Position = 2 )]
        [switch] $Aos,

        [Parameter(Mandatory = $false, ParameterSetName = 'Specific', Position = 3 )]
        [switch] $ManagementReporter,

        [Parameter(Mandatory = $false, ParameterSetName = 'Specific', Position = 4 )]
        [switch] $DIXF
    )

    if ($PSCmdlet.ParameterSetName -eq "Specific") {
        $All = $false
    }

    Write-PSFMessage -Level Verbose -Message "The PSBoundParameters was" -Target $PSBoundParameters

    $aosname = "w3svc"    
    $ManagementReporter = "MR2012ProcessService"
    $dixfname = "Microsoft.Dynamics.AX.Framework.Tools.DMF.SSISHelperService.exe"

    [System.Collections.ArrayList]$Services = New-Object -TypeName "System.Collections.ArrayList"

    if ($All) {
        $null = $Services.AddRange(@($aosname, $ManagementReporter))
    }    
    else {
        if ($Aos) {
            $null = $Services.Add($aosname)
        }
        if ($ManagementReporter) {
            $null = $Services.Add($ManagementReporter)
        }
        if ($DIXF) {
            $null = $Services.Add($dixfname)
        }
    }

    $Services.ToArray()
}