I have about 2000 folders that I need to move and am looking for a bit of a better way than just copy/pase the rename.
Current folder structure is like this Job>Asset>Reports. What I am trying to do is consolidate all of the reports folders (and all of the files) under a single folder, and rename just the Reports folder to the Asset name.
Currently in my test folder I have this code working to copy over the folder and contents, but I can’t get it to rename so it just fails after copying over the first folder.
Get-ChildItem -path “C:Test Source” -include “Reports” -recurse | Copy-Item -Destination “C:Test Destination” -recurse -container | Rename-Item -NewName {$_.Directory.Parent.Name}
I’m assuming that the issues is somewhere in how I am setting up the Rename-Item, as it’s not renaming the folder after it’s copied to the new location. I also don’t want to rename the report folders in the original path, just the new one.
Thanks for the help!
Cole Sunderman is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.