PowerShell Move Folders and Files

Twhite0909
Twhite0909 used Ask the Experts™
on
I use the Move-Item cmdlet currently to move files from my SFTP to other locations.  I now wantr to move the FOLDERS and FILES from the server to other locations.

Move-Item D:\LocationA\*    Grabs all files under the LocationA directory but does not move any subfolders residing here.
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Most Valuable Expert 2018
Distinguished Expert 2018

Commented:
You need to specify the folder as source, not child items (with the \* at the end) to move th complete folder:
Move-Item -Path "D:\LocationA" -Destination "D:\LocationB"

Open in new window

Author

Commented:
OK TY for that now second part is I am moving it across volumes of different servers. I have a mapped network drive for the other servers location but this script gives an error " Move-Item : Source and destination path must have identical roots. Move will not work across volumes."
Most Valuable Expert 2018
Distinguished Expert 2018
Commented:
Just use robocopy instead. Note that robocopy's second argument is the target folder where the files (and subfolders) from inside the source folder will be placed. So if you want to keep the original source folder in the target as well, you need to specify it in the target path:
& robocopy.exe "D:\LocationA" -Destination "E:\Target\LocationA" /e /r:0 /move

Open in new window

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial