Get individual names of services in ServiceSet during test-dscconfiguration

Welcome Forums DSC (Desired State Configuration) Get individual names of services in ServiceSet during test-dscconfiguration

This topic contains 2 replies, has 2 voices, and was last updated by

2 years, 3 months ago.

  • Author
  • #57757

    Points: 0
    Rank: Member

    I have a configuration that uses ServiceSet resource as shown below
    ServiceSet myserviceset

    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

    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

    Points: 1,811
    Helping HandTeam Member
    Rank: Community Hero

    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

    Points: 0
    Rank: Member

    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

    #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 | ft

The topic ‘Get individual names of services in ServiceSet during test-dscconfiguration’ is closed to new replies.

denizli escort samsun escort muğla escort ataşehir escort kuşadası escort