PowerShell Move Folders and Files

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.
Twhite0909Asked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

oBdACommented:
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

0
Twhite0909Author 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."
0
oBdACommented:
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

1

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Powershell

From novice to tech pro — start learning today.