Converting the FileSystemObject's Copy Method

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


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