PowerShell is so cool…
I had no idea how to automate Outlook with COM before today. Took me about 5 minutes to learn how with PowerShell. I knew it could be done with VBS, right? That’s how viruses are made.
This won’t be a long blog unfortunately, but wanted to paste real quick a series of commands which I basically figured out in a shell interactively. I didn’t have to read any docs, Get-Member told me all I needed to know.
I did go back and add some comments. I hope you find it useful.
$ol = New-Object -com Outlook.Application # starts outlook
$ol.Reminders | select caption, nextreminderdate # show reminders
$ol | gm -mem method # show all methods (actions) on the com object
$n = $ol.CreateItem('olNoteItem') # creates a note
$n # display note object
$n.Body = 'test' # set body of note
$n | gm # display object members (methods & properties) of note
$n.Display() # show note
$n.Color # display color value
$n.Color = 4 # set color
1..5 | ForEach-Object { $n.Color = $_; sleep 1 } # change color of note 5 times
$m = $ol.CreateItem('olMailItem') # create mail object
$m # display mail object
$m | gm -mem property # show mail properties
$m.Subject = 'test' # set subject
$m.Body = 'test' # set body
$m.To = 'email@domain.com' # set to address
$m.Display() # display mail item on screen
$m.Send() # send mail item
$ol # display outlook object
$ol | gm # display outlook methods

No comments yet.