THE SQL Server Blog Spot on the Web

Welcome to SQLblog.com - The SQL Server blog spot on the web Sign in | |
in Search

Buck Woody

Carpe Datum!

Create Outlook Appointments from PowerShell

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"

$appt.Save()

 

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.

 

Published Wednesday, March 10, 2010 8:33 AM by BuckWoody

Comment Notification

If you would like to receive an email when updates are made to this post, please register here

Subscribe to this post's comments using RSS

Comments

 

James Luetkehoelter said:

Very nice Buck! I remember having to do this for a client with the old CDO libraries, OA sps and Exchange 5.5...

March 10, 2010 1:49 PM

Leave a Comment

(required) 
(required) 
Submit

About BuckWoody

http://buckwoody.com/BResume.html

This Blog

Syndication

Powered by Community Server (Commercial Edition), by Telligent Systems
  Privacy Statement