Examples/Sample_Service_CreateService.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
<#
    .SYNOPSIS
        If the service with the name Service1 does not exist, creates the service with the name
        Service1 and the executable/binary path 'C:\FilePath\MyServiceExecutable.exe'. The new
        service will be started by default.
 
        If the service with the name Service1 already exists, sets executable/binary path of the
        service with the name Service1 to 'C:\FilePath\MyServiceExecutable.exe' and starts the
        service by default if it is not running already.
#>

Configuration Sample_Service_CreateService
{
    [CmdletBinding()]
    param
    ()

    Import-DscResource -ModuleName 'PSDscResources'

    Node localhost
    {
        Service ServiceResource1
        {
            Name = 'Service1'
            Ensure = 'Present'
            Path = 'C:\FilePath\MyServiceExecutable.exe'
        }
    }
}