Author Posts

November 15, 2016 at 4:05 pm

Problem:
I have a configuration that uses ServiceSet resource as shown below
ServiceSet myserviceset
{
Name=@("AppReadiness","AppIDSvc")
State="Running"
}

I apply the configuration and turn off only one service viz "AppReadiness". Now i execute Test-DSCConfiguration command as follows

$myvar=Test-DscConfiguration -ComputerName "DESKTOP-2F446SK" -Detailed | select ResourcesNotInDesiredState
$rninds=$myvar | select -ExpandProperty ResourcesNotInDesiredState
$rnids

As you can see when i print the contents of $rnids representing "resources not in desired state", I dont see the actual service name instead i see the instance name as "Resource0::[ServiceSet]myserviceset"

Question: How do i get the actual servicename that is not in the desired state when i use ServiceSet resource. This problem applies to all resource sets such as "ProcessSet", "WindowsFeatureSet", "WindowsOptionalFeatureSet", "GroupSet" etc.

Any help is highly appreciated.

November 15, 2016 at 4:46 pm

I'm not sure you can. The idea with the set is that it's atomic – it's a single all-or-nothing unit; breaking it down into components defeats the "set" concept. If that's what you need, you'd do individual settings.

November 15, 2016 at 9:06 pm

Thanks Don.
However i scripted a PS to generate the report to satisfy my needs. The problem with this is it works on current configuration only and not on reference configuration.

#reports all resources in desired and not-destired states in a single table
#handles ServiceSet so that individual services are shown in the report
cls

#capture resources not in desired state from Test-DSCConfiguration result
$myvar=Test-DscConfiguration -ComputerName "DESKTOP-2F446SK" -Detailed | select ResourcesNotInDesiredState

#expand the property
$rinds=$myvar | select -ExpandProperty ResourcesInDesiredState

#we are only interested in some columns so pick only those
$finalrnids=$rninds | select ResourceID, ResourceName, InstanceName, DependsOn, InDesiredState

#create a mapping of all ResourceID->Name from the current applied configuration
#this map is used to get actual service names
$resourcemap=Get-DscConfiguration | Select ResourceID, Name

[array] $final= @()
foreach($x in $finalrnids)
{
$resdetail = New-Object PSObject
#get the actual service name from resourceid
$name=$resourcemap | where {$_.ResourceID -eq $x.ResourceID} | Select Name
$resdetail | add-member -type NoteProperty -Name ResourceName -Value $x.ResourceName
$resdetail | add-member -type NoteProperty -Name InstanceName -Value $name.Name
$resdetail | add-member -type NoteProperty -Name DependsOn -Value $x.DependsOn
$resdetail | add-member -type NoteProperty -Name InDesiredState -Value $x.InDesiredState
$final+=$resdetail
}

$final | ft