DependsOn Foreach Loop

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

  • Author
    Posts
  • #67666
    Profile photo of TommyQuality
    TommyQuality
    Participant

    Hi,

    Is it possible to set a depends on for a foreach loop, i.e i have a foreach loop dsc group resource

    Node $AllNodes.Where{$_.Role -eq "IIS"}.NodeName 
    {
    $Node.Groups.ForEach({
                
    Group $_.Group  
            {
                GroupName = $_.Group
                Ensure ="Present"
                MembersToInclude = $_.Members
                Description = $_.Description
            } 
        })
    

    I then have another resource that is dependent on the foreach Group $._Group. I have set the depends on to

    DependsOn =[Group]$_.Group

    but this fails whith the error dependency doesn't exist.

    Thanks

    Tom

  • #67668
    Profile photo of Don Jones
    Don Jones
    Keymaster

    Outside the ForEach loop, $_ has no meaning. So in the dependent resource, you can't use $_ – you need to use whatever $_ is resolving to.

  • #67672
    Profile photo of TommyQuality
    TommyQuality
    Participant

    Okay, Thanks Don.

You must be logged in to reply to this topic.