DependsOn Foreach Loop

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

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

Okay, Thanks Don.