While at the PowerShell Conference EU, we had some very good discussions around PowerShell and PowerShell DSC. A few questions came up about DSC composite resources and how they are being used. DSC composite resources are essentially configurations packaged as resource modules. The benefit is that you can discover them like other DSC resource modules and use them like that. There is a good overview and information on authoring Composite resources on MSDN. So, if you are completely new to this concept, I suggest you read the article first before proceeding.
TL;DR: If you already know about what DSC composite resources are and how they work, We would like to understand a few aspects around composite resources. Here is a small survey for you: https://www.surveymonkey.com/r/6K6FGTR.
In the following example, I am using the ServiceSet composite resource that comes with Windows Server 2016 TP4.
Instead of specifying multiple instances of Service resource, we can use the ServiceSet to configure multiple services that need to be configured in a similar way. Here is an example of the configuration that uses ServiceSet composite resource.
1
2
3
4
5
6
7
8
9
10
11
| Configuration DemoComposite {
Import-DscResource -ModuleName PSDesiredStateConfiguration
ServiceSet ServiceSetComposite {
Name = 'audiosrv','winmgmt'
Ensure = 'Present'
}
}
DemoComposite -OutputPath C:\DemoComposite
Start-DscConfiguration -Path C:\DemoComposite -Force -Wait -Verbose
|
Once you enact this configuration and use the Get-DscConfiguration cmdlet, you will see that the ServiceSet resource gets expanded into the two Service resource instances defined in the configuration.
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
| PS C:\> Get-DscConfiguration
ConfigurationName : DemoComposite
DependsOn :
ModuleName : PSDesiredStateConfiguration
ModuleVersion : 1.1
PsDscRunAsCredential :
ResourceId : [Service]Resource0::[ServiceSet]ServiceSetComposite
SourceInfo :
BuiltInAccount : LocalService
Credential :
Dependencies : {AudioEndpointBuilder, RpcSs}
Description : Manages audio for Windows-based programs. If this service is stopped, audio devices and effects will not function properly. If this service is
disabled, any services that explicitly depend on it will fail to start
DisplayName : Windows Audio
Ensure :
Name : audiosrv
Path : C:\Windows\System32\svchost.exe -k LocalServiceNetworkRestricted
StartupType : Manual
State : Running
Status :
PSComputerName :
CimClassName : MSFT_ServiceResource
ConfigurationName : DemoComposite
DependsOn :
ModuleName : PSDesiredStateConfiguration
ModuleVersion : 1.1
PsDscRunAsCredential :
ResourceId : [Service]Resource1::[ServiceSet]ServiceSetComposite
SourceInfo :
BuiltInAccount : LocalSystem
Credential :
Dependencies : {RPCSS}
Description : Provides a common interface and object model to access management information about operating system, devices, applications and services. If this
service is stopped, most Windows-based software will not function properly. If this service is disabled, any services that explicitly depend on it will
fail to start.
DisplayName : Windows Management Instrumentation
Ensure :
Name : winmgmt
Path : C:\Windows\system32\svchost.exe -k netsvcs
StartupType : Automatic
State : Running
Status :
PSComputerName :
CimClassName : MSFT_ServiceResource
|
Now, for some people, this may not make sense. In the configuration script, we have only one resource but in the Get-DscConfiguration output, we have two service instances. This can be confusing at times. The same applies to the Test-DscConfiguration cmdlet as well.
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
| PS C:\> Test-DscConfiguration -Detailed | Select -ExpandProperty ResourcesInDesiredState
ConfigurationName : DemoComposite
DependsOn :
ModuleName : PSDesiredStateConfiguration
ModuleVersion : 1.1
PsDscRunAsCredential :
ResourceId : [Service]Resource0::[ServiceSet]ServiceSetComposite
SourceInfo : ::2::1::Service
DurationInSeconds : 0
Error :
FinalState :
InDesiredState : True
InitialState :
InstanceName : Resource0::[ServiceSet]ServiceSetComposite
RebootRequested : False
ResourceName : Service
StartDate : 4/22/2016 6:50:41 PM
PSComputerName : localhost
ConfigurationName : DemoComposite
DependsOn :
ModuleName : PSDesiredStateConfiguration
ModuleVersion : 1.1
PsDscRunAsCredential :
ResourceId : [Service]Resource1::[ServiceSet]ServiceSetComposite
SourceInfo : ::8::1::Service
DurationInSeconds : 0.015
Error :
FinalState :
InDesiredState : True
InitialState :
InstanceName : Resource1::[ServiceSet]ServiceSetComposite
RebootRequested : False
ResourceName : Service
StartDate : 4/22/2016 6:50:41 PM
PSComputerName : localhost
|
You can identify the resource instances that belong to the composite resource configuration using the InstanceName property. However, it is not always desired.
Instead of this expansion, it will be helpful if the Get and Test methods roll-up the status of the resource instances from the composite resource configuration into a single instance.
So, here is a survey for you. Vote it up and let the team know what your preference is.
Share on: