Author Posts

October 20, 2016 at 9:32 pm

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
            $ctr++
            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!

October 20, 2016 at 10:56 pm

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.