DSC tries to start service I set to manual, and errors out on it

I have the following DSC resource:

    Service sacsvrManual {

Notice that there is no State mentioned. But when it runs, I get the following, indicating it tested it and decided that it needed to be RUNNING:

VERBOSE: [MTS1020]: LCM: [ Start Resource ] [[Service]sacsvrManual]
VERBOSE: [MTS1020]: LCM: [ Start Test ] [[Service]sacsvrManual]
VERBOSE: [MTS1020]: LCM: [ End Test ] [[Service]sacsvrManual] in 0.0160 seconds.
VERBOSE: [MTS1020]: LCM: [ Start Set ] [[Service]sacsvrManual]
VERBOSE: [MTS1020]: [[Service]sacsvrManual] Service ‘sacsvr’ already exists. Write properties such as Status, DisplayName,
Description, Dependencies will be ignored for existing services.
VERBOSE: [MTS1020]: LCM: [ End Set ] [[Service]sacsvrManual] in 2.5780 seconds.
PowerShell DSC resource MSFT_ServiceResource failed to execute Set-TargetResource functionality with error message: Failure starting service
‘sacsvr’. Please check the path ‘C:\Windows\System32\svchost.exe -k netsvcs’ provided for the service. Message: ‘Exception calling “WaitForStatus”
with “2” argument(s): “Time out has expired and the operation has not been completed.”’
+ CategoryInfo : InvalidOperation: (:slight_smile: [], CimException
+ FullyQualifiedErrorId : ProviderOperationExecutionFailure
+ PSComputerName : MTS1021

I can’t figure out why it is deciding to start the service.

The Service resource is probably defaulting the State property.

What’s the goal? To ensure that the service is set to Manual but not care if it’s currently running or not?

Exactly. Set it to manual but leave its state in place.

I’d probably just do this with a custom resource, or even a quick Script resource. Get-Service and Set-Service can obviously do that easily.

Thanks Don, that has occurred to me, but with the number of services I’m setting to manual, I’m thinking of combining them into a single script resource and just have it run every time. It’s too cumbersome to do a script for each service.

By the way, I checked the MOF that was generated, and there was nothing about State in it; powershell correctly generated the MOF as far as I can tell, it seems like something the LCM is doing.

Well, keep in mind that the point of DSC is for each resource to be idempotent. Id you want, just knock out a quick DSC resource module that can set a service’s start mode only, and then call that for each service.

It wouldn’t be the LCM doing it. The LCM doesn’t do anything but run resources; have a look at the Service resource - it’s what’s doing the work.