Copy Files with Powershell in XP as Scheduled TaskPosted: March 9, 2011
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:
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.