4

#PSTip Copying folders using Copy-VMFile cmdlet in Windows Server 2012 R2 (Hyper-V)

In an earlier article, I showed you how to use the Copy-VMFile cmdlet. However, if you have paid attention and really used it, you will know that it cannot be used to copy a folder completely with its contents in a recursive manner.

Copying each and every single file isn’t a great experience, right?

Let us see how we can copy a complete folder to a VM.

Get-ChildItem C:\Scripts -Recurse -File | % { Copy-VMFile "WC7-1" -SourcePath $_.FullName -DestinationPath $_.FullName -CreateFullPath -FileSource Host }

Observe the -File switch parameter in the command above. It is needed because the Copy-VMFile is capable of copying files only. So, if it encounters a folder, it simply fails. So, with the above command empty folders on the source path will not be created at the target because of the -File switch parameter.

Filed in: Columns, Tips and Tricks Tags: ,

4 Pingbacks/Trackbacks

4 Responses to "#PSTip Copying folders using Copy-VMFile cmdlet in Windows Server 2012 R2 (Hyper-V)"

Leave a Reply

Submit Comment

© 1442 PowerShell Magazine. All rights reserved. XHTML / CSS Valid.
Proudly designed by Theme Junkie.
%d bloggers like this: