Check SQL Server Jobs with Powershell

Standard

I like to automate as much as possible using scripts with SQL Server. So one of the things I want to know is if any job has failed in a list of servers. I’m a fan of Powershell because it’s so powerfull and is easy to develop.

This script uses Excel to write the status of the different jobs on a server.

The script can be run using two arguments:

  1. ServerList
  2. Output

ServerList

The server list parameter is a mandatory list that holds all the different instances that need to be checked. The file is a text file with on every new line a instance. Make sure the full instance is put in when a named instance is used like: SQL01\SQLEXPRESS or SQL01\name.

In case of a default instance only the name of the server needs to be put in.

Output

The ouput parameter is used when you don’t want to see the Excel sheets. Instead the scripts writes the file directly to the given folder.

Usage

The script can be used like this:

The code can be seen below:

 

 

Leave a Reply