Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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.

share|improve this question
up vote 1 down vote accepted

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.

share|improve this answer

Try this:

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:

share|improve this answer
thanks. I was under the impression that SQL2008 and Powershell shared some functionality, and that I might be able to do this based on the SQL schedule rather than just timing it with windows. This would work too - thanks for the pointers! – aSkywalker Nov 20 '09 at 19:56
You may well be able to use SQL scheduler, but I'm unfamiliar with it. "Whatever works" =) – Wesley Nov 20 '09 at 20:25
Indeed - I have set it up like this and put in a buffer of time that I expect the SQL maintenance plan will take to run. Gets the job done for now. If anyone else knows a way to run this within SQL Server please share – aSkywalker Nov 20 '09 at 20:42

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.