How does Move-Item compare to xcopy?

We have a PS script that currently tries to use xcopy to move some files along with all of their owners, permissions, etc.

#This copies all files in the default InetpubRoot location to a new location and transfers all ownership, permissions, etc. along with it
xcopy.exe $originalInetpubRoot $newInetPubRoot /O /X /E /H /K /F
#Variables are the old and the new filepaths for InetPubRoot

The problem is that PS doesn’t really seem to work with xcopy.exe (the script gets hung up on this step and won’t progress), so I would like to use something more native to PS like Move-Item. However, I don’t know how Move-Item works and what capabilities it has.

xcopy has a wonderful doc sheet on Microsoft’s website that lists every single switch and explains what each one does: xcopy | Microsoft Docs

/O copies file ownership and DACLs
/X copies audit settings and SACLs
/E copies all sub-directories

The Move-Item doc on Microsoft’s website does not have any of this information: Move-Item (Microsoft.PowerShell.Management) - PowerShell | Microsoft Docs

The closest item is using the -Recurse switch to include all child items.

So my question is: does Move-Item have the same capabilities as xcopy? If so, how do I use them? If not, is there a way to get xcopy to work correctly in my PS script?

For starters, Move-Item MOVES files whereas XCOPY copies files so they are technically not the same. Do you mean to use Copy-Item?

Move-Item seems to have all of the same (lack of) functions as Copy-Item, it just moves instead of copies.

We will be deleting all the files/folders at the old location when we are done anyways so using Move-Item would be simpler.

Understood. I am not aware of any more detailed info on Move-Item. I do know from experience that Move-Item will keep the permissions from the Source and NOT inherit in the destination. So keep that in mind. I had to massage the destination after a move to Inherit from the new location. I dont have that code in front of me now but can share that if needed when I do.

The number one tool to copy or move files on Windows systems is robocopy.

1 Like

I cant believe how many times I have used robocopy, and until now, did not know it had an option to move files.Thanks for that Olaf :slight_smile:

So you never actually read the help, have you? :wink: :stuck_out_tongue_winking_eye: :grimacing: :slight_smile: :kissing_heart:

Well … define “read the help” … I have done robocopy /? many times, but NEVER noticed (or needed) the /mov option. I also admit I only use it to copy, I never really move files. So yes, I have read the help, just not very thorough


1 Like