File resource in for loop for dynamic sources

This topic contains 1 reply, has 2 voices, and was last updated by  Don Jones 1 year, 8 months ago.

  • Author
  • #55465

    Sameer Kumar

    I have been trying to use File resource inside foreach loop for multiple sourcepath and single destination but it errors out stating that:

    Resources have identical key properties but there are differences in the following non-key properties: 'SourcePath'. Values '\\IM' don't match values '\\PowerShellGallery'. Please update these property values so that they are identical in both cases.

    Here is my POSH:

    foreach ($folder in Get-ChildItem -Recurse -Path "\\$ModulesDirectory" -Depth 0 -Directory)
                $folderName = $folder.Name
                File "DuplicateModulesFolder$ctr"
                    DestinationPath = "C:\Temp\1"
                    Checksum        = "ModifiedDate"
                    Ensure          = "Present"
                    Recurse         = $true
                    SourcePath      = "$ModulesDirectory\$folderName"
                    Type            = "Directory"
                    MatchSource     = $true
                    Credential = $runAsUserCred

    In this sample, $ModulesDirectory is UNC containing 2 nested folders IM and PowerShellGallery. I want to pull down files from UNC path into local drive. In future there may be multiple folders under $ModulesDirectory root dir.

    Thanks for your help!

  • #55472

    Don Jones

    Every resource defines specific properties that are its "keys," and each instance of that resource must have a unique key. I'm not in front of a computer to check, but I believe for the File resource it's DestinationPath. You can't have multiple blocks with the same DestinationPath.

You must be logged in to reply to this topic.