Powershell – Run PowerShell script within a maintenance plan

powershellsql-server-2008windows-server-2008

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.

Best Answer

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.

Related Topic