Making file copy easy.

I often run into questions concerning simple file copy during a SCCM/MDT Task Sequence.  There are many ways to accomplish this, but it seams most people wind up using the good old XCOPY command, and in general there is nothing wrong with that.

When copying from a DP though, you might run into problems when copying all files and folders in the root on your source, as that points to the root of X:\windows and not the root of the package specified..

Well to work around any issues I created a small VBS script, that takes care of the copying as long as it resides in the root of the source folder. There are of cause ways around the xcopy issues, and as I mentioned other ways to copy files, but this script solution seems to work every time…

So, how to use the script.

1. Copy code from the below script to a .vbs file (or download from the bottom of  the page)

2. Place the script in the folder containing the files/folders you intend to copy, and that folder to a package.

3. In your TS, Add a Run Command Line step, and call the script from the package

In this example I created a Package called Files To Copy which contains all the files and folders I want to copy (and of cause also the script, that I call CopFiles.vbs)


In the Command line: I typed in cscript.exe CopyFiles.vbs c:\TEST

This will copy everything in the package to C:\TEST and remove the CopyFiles.vbs script.


In case I only want to copy, say two files from the package, the syntax would be:

 cscript.exe CopyFiles.vbs c:\TEST file1.txt file2.txt

This would only copy file1.txt and file2.txt to the destination c:\TEST


In case I only want to copy, one file and one folder from the package, the syntax would be:

 cscript.exe CopyFiles.vbs c:\TEST file1.txt Folder1


In case I want to copy all TXT files the syntax would be:

 cscript.exe CopyFiles.vbs c:\TEST *.txt


The script is shown below


Download “CopyFiles” – Downloaded 7233 times – 1 KB

By | 2011-01-17T13:54:24+00:00 January 17th, 2011|General info, OS Deployment|24 Comments

About the Author:

Michael Petersen
Twitter: @OSDeployLinkedin: Michael PetersenMicrosoft Community Contributor


  1. Ian Broadbent August 10, 2011 at 9:44 - Reply

    Hi Michael, Thanks for this script! It makes copying files in SCCM reliable.
    I found I have to pre-create a directory structure if there is more than one sub-directory deep, but other than that it seems to work like a charm.

    A few minor typos in comments – but I know your English is better than my Danish! 🙂 Thanks again.

  2. Paul Faulkner December 12, 2011 at 10:14 - Reply

    Hi Michael, this is brilliant exactly what I have been looking for! Thanks for this.

  3. jonjon3s October 28, 2013 at 16:19 - Reply

    Great script, thanks for this – the only successful method I’ve found of getting a file copied to client. Many thanks!

    Only thing for me is it doesn’t appear to be able to handle folders with spaces in the names, i.e. “Program Files”,
    It throws error in line 43, oFSO.CopyFolder error path not found. But I’ll create a work around, use this script to copy to a temporary folder, then another command line to copy it where i need it!

  4. […] view source […]

  5. yesmarcs April 28, 2015 at 16:42 - Reply

    Thanks, Michael. This worked flawlessly.

  6. hari June 28, 2015 at 21:43 - Reply

    Hi Petersen,

    Thanks for this post. But i failed to create the TS. Can you please help me.

    3. In your TS, Add a Run Command Line step, and call the script from the package

    I didn;t understand this point.

  7. hari June 28, 2015 at 21:44 - Reply


    • FXR July 14, 2015 at 21:07 - Reply

      Are you still having problems with the TS?? mine works flawlessly, if you need any help let me know

  8. FXR July 14, 2015 at 21:05 - Reply

    Men Thank you so Much!!! Great Script, saved my life. Now i’ll start studying some PowerShell, is AWESOME!!!

  9. Joe April 20, 2016 at 16:12 - Reply

    The script has a typo in line 55 which results on an error when specifying a folder as source (“error: path not found”). Change

    oFSO.CopyFolder sSource & “” & sFileName, sTargetFolder& “” & sFileName, OverwriteExisting


    oFSO.CopyFolder sSource & “” & sFileName, sTargetFolder & “” & sFileName, OverwriteExisting

    (note the additional whitespace after sTargetFolder) and all is well.

  10. […] Back in the day anytime I needed to copy a file from server to client during a deployment, I was creating a new script from scratch. Eventually, I just started using a basic template. This was all of course, before I found the CoreTech file copy script. […]

  11. […] needed to copy some folder or some stupid ini to some random folder, but once I found this script: I just drop the script into a folder and call it as needed. You basically create a folder with what […]

  12. selim atmaca October 20, 2016 at 15:58 - Reply

    It works great, thanks!

  13. keywan October 21, 2016 at 12:07 - Reply

    If I create a Package I need to type on the Command line, what should I type there?

  14. keywan October 21, 2016 at 12:16 - Reply

    And what is cscript.exe?

  15. keywan October 21, 2016 at 13:46 - Reply

    Should the folder “TEST” exist on target machine?

  16. selim atmaca October 24, 2016 at 15:24 - Reply

    Hi Keywan,
    1. In Command line type this: cscript.exe CopyFiles.vbs C:UsersPublicDesktopHotKey (Here I am copying folder named Hotkey to C:UsersPublicDesktop. I am copying there because I want this folder exists on anyone’s desktop who logs on)

    2. With Cscript.exe, you can run scripts by typing the name of a script file at the command prompt

    3. the folder does not have to exist on the target machines. I tested already.

    • keywan October 26, 2016 at 10:01 - Reply

      Hi Selim,
      Thanks for your replay. You mean the folder does not have to exist on the target machines. but I have just try again with your command line and the Software Center says it is installed but I don`t see any folder there. Is that a permission issue?

  17. Marc November 21, 2016 at 21:13 - Reply

    Is there a way to copy files and folders to the root of the drive on the machine I’m deploying to? If I specify a folder such as C:test, everything goes into the root of the test folder. If I use C: for the target, files and folders go into the folder c:NameOfFolderOnServer

  18. frank December 19, 2016 at 13:41 - Reply

    Hi Marc,

    i tryed your script with mdt2013 with the basic usage but i dont see anything on the desitnation machine.

    i’am also missing the checkbox “package” in the 2013 “run command line script” task.

  19. frank December 19, 2016 at 16:43 - Reply

    sry marc, forget my last post. works as expected – sometimes shit’s realy deep …

    • Lars February 1, 2017 at 16:08 - Reply


      Can you explain what you did in MDT 2013, because i cant find the package checkbox.
      pls help.

    • Ronak April 27, 2017 at 10:49 - Reply

      I am also having the same issue, not able to find package checkbox in cmd. any suggestion?

Leave A Comment