Take the 2-minute tour ×
Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

I have a SQL 2008 database, run on 64 bit Win2008 Server. 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. Anyone have any tips, or another suggested way to schedule it to run?

It needs to run as admin - I know this is not ideal, but am hoping I can have it execute as admin. I currently open Powershell as admin, and execute the script manually every morning.

In case it matters, the script: zips the backup file (7z) 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 #2 spot deletes the bak files

I am new to powershell and am pretty pleased with the time savings so far from the script, but want it to run without counting on me to run it.

share|improve this question

2 Answers 2

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: 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

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.