Copy Files with Powershell in XP as Scheduled Task

I have a requirement to copy pdf files on my web server to a folder for FTP and another location for archiving. I have searched a while and came up with a Powershell script on my developer XP machine .

First  Ineed to run this command under Powershell command:

set-executionpolicy RemoteSigned

and I responded with yes to allow the Powershell script to run.

The script I wrote to copy files (only pdf file)  from one folder to two destination folders and the file is saved as copyFilesTest.ps1 in my test folder. The file extension is ps1.

Here is the code in the file:

# source and destionation folder

$source = “C:\test\jingyang”
$destination1  = “C:\tes\jingyang_destination1”
$destination2  = “C:\tes\jingyang_destination2”

$files = Get-ChildItem -Filter *.pdf -Path $source -Recurse

Foreach($file in $files)


Copy-Item -Path $file.fullname -Destination $destination1  -Force
Copy-Item -Path $file.fullname -Destination $destination2  -Force

After the test run of the script in Powershell, I create a bat file to execute the file. The file with .bat extension looks like this in my case:

powershell -command “& ‘C:\test\Scripts\copyFilesTest.ps1′”

Last, from Scheduled Task GUI, I setup a new task to point to the bat file I just created and pick a schedule time to run this script.



Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s