Get individual names of services in ServiceSet during test-dscconfiguration

This topic contains 2 replies, has 2 voices, and was last updated by Profile photo of vamsee vamsee 3 weeks, 1 day ago.

  • Author
    Posts
  • #57757
    Profile photo of vamsee
    vamsee
    Participant

    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.

  • #57764
    Profile photo of Don Jones
    Don Jones
    Keymaster

    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.

  • #57806
    Profile photo of vamsee
    vamsee
    Participant

    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

You must be logged in to reply to this topic.