Export (0) Print
Expand All
Expand Minimize

Converting the FileSystemObject's Copy Method


Windows PowerShell


Definition: Copy a single file or folder to another location.

Copy


PowerShell provides the Copy-Item cmdlet for copying files and folders. This example copies the file Test.txt from C:\Scripts to C:\Scripts\Temp:


Copy-Item C:\Scripts\Test.txt C:\Scripts\Temp


Pretty easy, right? This example copies the folder C:\Scripts\Temp - but not its content - to C:\Scripts\Old:


Copy-Item C:\Scripts\Temp C:\Scripts\old


To include the contents of the folder in the copy, use the -recurse parameter:


Copy-Item C:\Scripts\Temp C:\Scripts\old -recurse


The FileSystemObject Copy method includes a parameter that sets whether or not existing files and folders will be overwritten. By default Copy overwrites existing files. In PowerShell, the default is to not overwrite existing files. To overwrite existing files, use the -force parameter:


Copy-Item C:\Scripts\Temp C:\Scripts\old -force


See conversions of other FileSystemObject methods and properties.
Return to the VBScript to Windows PowerShell home page

Was this page helpful?
(1500 characters remaining)
Thank you for your feedback
Show:
© 2014 Microsoft