I have an SQL Server 2008 database, run on a 64-bit Windows Server 2008. I created a pretty simple PowerShell script that automates a bunch of tasks. I would like this script to run as part of our maintenance plan. How do I schedule it to run?
It needs to run as administrator - I know this is not ideal, but I am hoping I can have it execute as administrator. I currently open PowerShell as administrator and execute the script manually every morning.
In case it matters, the script:
- Zips the backup file (7-Zip) and moves it to our backup location
- Juggles some files - keeping the latest backup in a particular network location, and moving what was the most recent backup into the number two spot
- Deletes the .bak files
I want the script to run without counting on me to run it.
You can run your PowerShell script within SQL Server 2008 Agent (SQL Server's job scheduler). Using SQL Server Management Studio, create a SQL Server job and select a PowerShell job step. In the job step information specify the full path to your PowerShell script file.
Try this: http://www.searchmarked.com/windows/how-to-schedule-a-windows-powershell-script.php
In short, save the PowerShell script as a .ps1 file, make sure PowerShell will execute PowerShell scripts, create a bat file that calls powershell and feeds it your script and then schedule the .bat file.
And here's a juicy Google search for good measure: http://www.google.com/search?q=schedule+powershell+script