Author Posts

March 31, 2017 at 11:22 am

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

March 31, 2017 at 12:35 pm

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

March 31, 2017 at 1:05 pm

Okay, Thanks Don.