In Powershell can you use the copy-item command to copy all the contents of a directory including folders?

2k Views Asked by At

I know how to do it with different commands but is there a way to make it so copy-item cmdlet also copies directories to the target folder for example if I wanted to copy everything in the C:\users folder including all directories and sub directories is it possible to do with the copy-item command.

1

There are 1 best solutions below

1
On

You should be able to do it with:

copy-item C:\users -recurse

copy-item C:\users -destination c:\somewhereelse -recurse

The first way assumes you are currently in the destination folder, the second way is explicit.