To run a PowerShell Script from SSIS package
Posted: September 28, 2011 Filed under: Powershell, SQL SSIS 4 CommentsFrom this thread:
To run a PowerShell Script from SSIS package. Add a “Execute Process Task” in SSIS and use the following command text.
This works just great, plus the “-ExecutionPolicy ByPass” switch will take care of any server script policies.
C:\Windows\System32\WindowsPowerShell\v1.0\PowerShell.exe -ExecutionPolicy ByPass -command “. ‘L:\Powershell_Script\Script1.ps1’ ‘param1’ ‘param2′”
Copy Files with Powershell in XP as Scheduled Task
Posted: March 9, 2011 Filed under: Powershell Leave a commentI 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.
References:
http://technet.microsoft.com/en-us/library/ee176949.aspx
http://atakan.titiz.net/2008/01/schedule-powershell-script.html