Please feel free to provide feedback or file bugs here.

Double DependsOn in mof when using foreach loops

When using a foreach loop to create a set of resources and trying to set the previous item key as the dependsOn resource, it adds it twice in the mof file.

Configuration example:
configuration Test-DependsOnWithLoop {
param([string[]]$Directories)
Import-DscResource -ModuleName PSDesiredStateConfiguration
node localhost {
$dependsOn = $null
$dirs.ForEach({
$res = $_ -replace '\\|:', '_'
File $res {
Ensure = 'Present'
DestinationPath = $_
DependsOn = $dependsOn
Type = 'Directory'
}
$dependsOn = "[File]$res"
})
}
}

$dirs = 1..10 | % { "C:\Temp\_$_" }
Test-DependsOnWithLoop -Directories $dirs

And if you look at the localhost.mof you'll see:
DependsOn = { "[File]C__Temp__1", "[File]C__Temp__1"};

I traced it back to the Test-DependsOn function in CimDSCParser.cs, though in this case, it's not a composite resource

3 votes
Sign in
Check!
(thinking…)
Reset
or sign in with
  • facebook
  • google
    Password icon
    Signed in as (Sign out)

    We’ll send you updates on this idea

    Martin Schvartzman shared this idea  ·   ·  Flag idea as inappropriate…  ·  Admin →

    0 comments

    Sign in
    Check!
    (thinking…)
    Reset
    or sign in with
    • facebook
    • google
      Password icon
      Signed in as (Sign out)
      Submitting...

      Feedback and Knowledge Base