I’ve been toying around with a script to create a special set of calendar objects in Outlook that show when my SQL Server Agent Jobs are scheduled to run. I haven’t finished yet, but I thought I would share the part that creates the Outlook Appointments.I have yet to fill a variable with the start and end times, and then loop through that to create the appointments. I’m thinking I’ll make the script below into a function, and feed it those variables in a loop. The script below creates a whole new Calendar Folder in Outlook called “SQL Server Agent Jobs”. I also use categories quite a bit, so you’ll see that too.
Caution: If you plan to play with this script, do it on an isolated workstation, not on your “regular” Outlook calendar. Otherwise, you’ll have lots of appointments in there that you don’t care about!
# Add a new calendar item to a new Outlook folder called “SQL Server Agent Jobs”
$outlook = new-object -com Outlook.Application
$calendar = $outlook.Session.folders.Item(1).Folders.Item(“SQL Server Agent Jobs”)
$appt = $calendar.Items.Add(1) # == olAppointmentItem
$appt.Start = [datetime]”03/11/2010 11:00″
$appt.End = [datetime]”03/11/2009 12:00″
$appt.Subject = “JobName”
$appt.Location = “ServerName”
$appt.Body = “Job Details”
$appt.Categories = “SQL server Agent Job”
Script Disclaimer, for people who need to be told this sort of thing:
Never trust any script, including those that you find here, until you understand exactly what it does and how it will act on your systems. Always check the script on a test system or Virtual Machine, not a production system. All scripts on this site are performed by a professional stunt driver on a closed course. Your mileage may vary. Void where prohibited. Offer good for a limited time only. Keep out of reach of small children. Do not operate heavy machinery while using this script. If you experience blurry vision, indigestion or diarrhea during the operation of this script, see a physician immediately.