DscResources/ServiceSet/ServiceSet.schema.psm1

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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
$errorActionPreference = 'Stop'
Set-StrictMode -Version 'Latest'

# Import ResourceSetHelper for New-ResourceSetConfigurationScriptBlock
$script:dscResourcesFolderFilePath = Split-Path -Path $PSScriptRoot -Parent
$script:resourceSetHelperFilePath = Join-Path -Path $script:dscResourcesFolderFilePath -ChildPath 'ResourceSetHelper.psm1'
Import-Module -Name $script:resourceSetHelperFilePath

<#
    .SYNOPSIS
        A composite DSC resource to configure a set of similar Service resources.
 
    .DESCRIPTION
        A composite DSC resource to configure a set of similar Service resources.
 
    .PARAMETER Name
        An array of the names of the services to configure.
 
    .PARAMETER Ensure
        Specifies whether or not the set of services should exist.
 
        Set this property to Present to modify a set of services.
        Set this property to Absent to remove a set of services.
 
    .PARAMETER StartupType
        The startup type each service in the set should have.
 
    .PARAMETER BuiltInAccount
        The built-in account each service in the set should start under.
 
        Cannot be specified at the same time as Credential.
 
        The user account specified by this property must have access to the service
        executable paths in order to start the services.
 
    .PARAMETER State
        The state each service in the set should be in.
        From the default value defined in Service, the default will be Running.
 
    .PARAMETER Credential
        The credential of the user account each service in the set should start under.
 
        Cannot be specified at the same time as BuiltInAccount.
 
        The user specified by this credential will automatically be granted the Log on as a Service
        right. The user account specified by this property must have access to the service
        executable paths in order to start the services.
#>

Configuration ServiceSet
{
    [CmdletBinding()]
    param
    (
        [Parameter(Mandatory = $true)]
        [ValidateNotNullOrEmpty()]
        [System.String[]]
        $Name,

        [Parameter()]
        [ValidateSet('Present', 'Absent')]
        [System.String]
        $Ensure,

        [Parameter()]
        [ValidateSet('Automatic', 'Manual', 'Disabled')]
        [System.String]
        $StartupType,

        [Parameter()]
        [ValidateSet('LocalSystem', 'LocalService', 'NetworkService')]
        [System.String]
        $BuiltInAccount,

        [Parameter()]
        [ValidateSet('Running', 'Stopped', 'Ignore')]
        [System.String]
        $State,

        [Parameter()]
        [ValidateNotNull()]
        [System.Management.Automation.PSCredential]
        [System.Management.Automation.Credential()]
        $Credential
    )

    $newResourceSetConfigurationParams = @{
        ResourceName = 'Service'
        ModuleName = 'PSDscResources'
        KeyParameterName = 'Name'
        Parameters = $PSBoundParameters
    }

    $configurationScriptBlock = New-ResourceSetConfigurationScriptBlock @newResourceSetConfigurationParams

    # This script block must be run directly in this configuration in order to resolve variables
    . $configurationScriptBlock
}