1

Files: Powershell command to copy a file to another directory

Posted February 18th, 2010 in file, powershell and tagged , , , , , by dirk adamsky

Okido, here’s my first powershell script (or command line).

The action I want to accomplish is to copy a file to another directory.
I installed powershell v2 on my machine.

To open the powershell prompt you can do next steps:

  • give ‘windows key + r’ (opens ‘Start=>Run’)
  • give ‘powershell’ without the quotes
  • the powershell prompt now opens

When you want to change the working directory give cd followed by the full path, for example ‘cd c:temp’ (without quotes).

After changing the working directory it is time for action.
In ‘c:temp’ I created a file named ‘test.txt’ and a directory called ‘c:temptest’.
The powershell command to copy ‘test.txt’ to the ‘test’ directory is:


copy-item c:temptest.txt c:temptest

The result is that the file test.txt is copied to c:temptesttest.txt.
Instead of using copy-item you can also use the aliases ‘cp’ or ‘cpi’.

Happy scripting.

Best regards,

Dirk Adamsky – Deludi BV


Related Posts:
  • VBscript and WMI: VBscript to find files with specific extensions and creation date on remote servers
  • Active Directory: VBscript to enumerate the roaming profile size of all users in Active Directory
  • Filesystem: VBscript to enumerate the subfolders (recursive) with depth limit

  • One Response so far.

    1. This is a good post, please continue the good work with this blog!

    Leave a Reply