Set multiple services to run under the built-in account LocalService

Description

This example shows how you can use the ServiceSet composite resource to ensure multiple services exist and run under the LocalService built-in account.

With Ensure set to Present, BuiltInAccount set to LocalService, and Name set tthe array of Dhcp and SstpSvc, the resource configures the Dhcp and SstpSvc services to run under the LocalService account if they're configured to run under any other account.

With State set to Ignore, the resource doesn't start or stop the services.

If either service doesn't exist, the resource raises an exception. The ServiceSet composite resource can't create services, only manage or remove existing ones. To create a service if it doesn't exist, use the Service resource.

With Invoke-DscResource

The Invoke-DscResource cmdlet doesn't support invoking composite resources. Instead, use the Service resource.

With a Configuration

This snippet shows how you can define a Configuration with a ServiceSet resource block to ensure that the Dhcp and SstpSvc services run under the LocalService built-in account.

Configuration SetBuiltInAccount {
    Import-DscResource -ModuleName 'PSDscResources'

    Node localhost {
        ServiceSet ExampleServiceSet {
            Name           = @(
                'Dhcp'
                'SstpSvc'
            )
            Ensure         = 'Present'
            BuiltInAccount = 'LocalService'
            State          = 'Ignore'
        }
    }
}