Hello All
New to Powershell and this forum so please bear with me
I have a requirement to copy a handful of files in my source directory over every instance of that filename in my destination directory (including instances in sub-folders)
I have this so far:-
$sourceDirectory = “C:\Source”
$destinationDirectory = “C:\Destination”
$sourceFolders = Get-ChildItem -Path $sourceDirectory | Select-Object -ExpandProperty Name
$destinationFolders = Get-ChildItem -Path $destinationDirectory | Select-Object -ExpandProperty Name
$matchesInBoth = $sourceFolders | Where-Object{$destinationFolders -contains $}
$matchesInBoth | ForEach-Object{
$sourcePath = (Join-Path $sourceDirectory $)
Copy-Item -Path $sourcePath -Destination $destinationDirectory -Recurse
}
This copies successfully over the matching file names in the root of “C:\Destination” but not over the matching file names within the sub-folders of C:\Destination
Plenty of googling and playing with the syntax but this remains as close as I can get.
Help greatly appreciated
Adam