compare 1 domain network share folder to 1 local folder
if any new files are found on network share OR if any files have changed, then copy/overwrite.
I’ve been working on the below code but a few issues…
the script copies files over but the folder in which the file is found…
so if filea.jpg is in folder “folder1”, then inside “folder1” I will find another “folder1” which is empty…
Also if a file is only found in the source then the script fails with:
Copy-Item : Cannot find path blablablabla\sourceonlyfile.jpg
#Leaving out folders… but what if there’s a new folder in source??
$Source=Get-ChildItem $SourceFolder -recurse | Where-Object {!($.PSContainer)}
$Destination=Get-Childitem $LocalFolder -Recurse | Where-Object {!($.PSContainer)}
I’ll offer that Robocopy.exe would be much better, and much faster, and much more accurate. And it runs fine from within PowerShell.
However, please be careful in responding to your own post as the first response. That removes you from the “Topics With No Replies” list, which is what most of us use to find posts that still need attention.
Thanks … I’ve thought about robocopy but I’d really really like to keep it native to PS.
I’m using the below code now… and it’s working wonderfully but 1 issue… if I create 1 folder and then nest another folder inside it… it will create the first folder first, then create the first folder again inside the newly created folder… along with the nested folder…