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!