PowerShell Cookbook

Search

Categories

 

On this page

Outlook Automation in PowerShell - Calendar Scrubbing

Archive

Blogroll

Disclaimer
I work for Microsoft.

The opinions expressed herein are my own personal opinions and do not represent my employer's view in any way.

RSS 2.0 | Atom 1.0 | CDF

Send mail to the author(s) E-mail

Total Posts: 218
This Year: 18
This Month: 0
This Week: 0
Comments: 529

Sign In

 Wednesday, December 13, 2006
Thursday, December 14, 2006 7:45:39 AM (Pacific Standard Time, UTC-08:00) ( )

Here's one thing you might have noticed happening to your Outlook calendar. As time goes on, the calendar titles get obscured by the ugly meeting barnacles such as "FW: " and "Updated: ". I don't know anybody that cares about that meta-data, but it lives on -- and I'd like to remove it.

Omar Shahine mentioned that he wrote an Outlook addin to do this once. Since I've been doing some mail management tasks with PowerShell lately (more on that in future posts,) I thought it might be a useful thing to demonstrate via Outlook's Outlook.Application COM object.

The script below is quite simple. Run "Set-CalendarTitles," watch the pretty progress bar, and enjoy your newly clean calendar.

##############################################################################
## Set-CalendarTitles.ps1
##
## Clean calendar titles to remove:
## "FW: ", "Updated: "
##############################################################################

function main
{
    ## Create the outlook application object, and connect to the calendar
    ## folder
    $olApp = new -com Outlook.Application
    $namespace = $olApp.GetNamespace("MAPI")
    $fldCalendar = $namespace.GetDefaultFolder(9)

    "Gathering calendar items"
    $items = $fldCalendar.Items

    ## Visit each item, updating progress as we go
    $counter = 0
    foreach($item in $items)
    {
        $status = "Processing item {0} of {1}: {2}" -f $counter,$items.Count,$item.Subject
        Write-Progress "Processing calendar items" $status -PercentComplete ($counter / $items.Count * 100)

        ## Remove the extra text
        cleanItem $item "FW: "
        cleanItem $item "Updated: "

        $counter++
    }
}

## Clean the title of a calendar entry if it matches
## searchString
function cleanItem($item, $searchString)
{
    if($item.Subject -match $searchString)
    {
        $item.Subject = $item.Subject -replace $searchString,""
        $item.Save()
    }
}

. main
Comments [5] | | #