Copy-Item Container parameter

The Copy-Item Container parameter controls whether the folder structure is also copied.

Lets start with the source material – a folder C:\test with a bunch of files. A destination folder C:\D1 also exists

PS>  Copy-Item -Path c:\test\* -Destination C:\D1

copies the files from test to D1

PS>  Copy-Item -Path c:\test -Destination C:\D1

copies the FOLDER test to D1 BUT NOT the files in the folder

PS>  Copy-Item -Path c:\test -Destination C:\D1 –Recurse

copies the FOLDER and its FILES to D1.  test becomes a subfolder of D1

PS>  Copy-Item -Path c:\test -Destination C:\D1 -Recurse –Container

copies the FOLDER and its FILES to D1.  test becomes a subfolder of D1

PS>  Copy-Item -Path c:\test -Destination C:\D1 -Recurse -Container:$false

Copies the files from test to D1

If the destination folder DOESN’T exist

PS>  Copy-Item -Path c:\test -Destination C:\D2

creates just the folder

PS>  Copy-Item -Path c:\test -Destination C:\D2 –Recurse

PS>  Copy-Item -Path c:\test -Destination C:\D2 -Recurse –Container

Copy-Item -Path c:\test -Destination C:\D2 -Recurse -Container:$false

All create the folder and copies the files into it

These examples should enable you to utilise the –Container parameter as appropriate.

Advertisements
This entry was posted in Powershell. Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s