PowerShell Cookbook

Search

Categories

 

On this page

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: 222
This Year: 0
This Month: 0
This Week: 0
Comments: 536

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] | | # 
Wednesday, October 03, 2007 11:34:18 PM (Pacific Daylight Time, UTC-07:00)
Love the examples. However, I've recently tripped up on a problem with even trying to invoke a reference to the Outlook COM interface. I've used the lines "$olApp = new -com Outlook.Application" and "$olApp = New-Object Microsoft.Office.Interop:Outlook". Both fail. The errors are, "New-Object : Retrieving the COM class factory for component with CLSID {0006F03A-0000-0000-C000-000000000046} failed due to the following error: 80080005." and "New-Object : Cannot find type [Microsoft.Office.Interop:Outlook]: make sure the assembly containing this type is loaded", respectively.

Any thoughts? I'm on Outlook 2007 and Vista. I've checked to ensure that .net programmability for Outlook is installed. Damned if I can figure out a next step.

[Not sure if you'll even respond, as this is such an old post, but what the heck.]
Thursday, October 04, 2007 2:17:00 PM (Pacific Daylight Time, UTC-07:00)
Hi Steve;

I think you might be having a problem with the colon between Interop and Outlook. Here's an example of somebody using the interop libraries: http://www.muscetta.com/2007/05/30/death-by-right-click-delete-nope-powershell/

Lee
Thursday, October 04, 2007 5:32:12 PM (Pacific Daylight Time, UTC-07:00)
Hey Lee - Thanks for the suggestion but continues to "not work". Of note, neither the method your scripts typically use ("-com Outlook.Application") nor the interop assemblies method work. I'm assuming that there is no other Powershell configuration work I need to do to make this function, correct?

Interestingly, the suggested line, in the link you reference, "[System.Reflection.Assembly]::LoadWithPartialName('Microsoft.Office.Interop.Outlook')" does succeed. Unfortunately, any instantiations of a new outlook object reference after it still do not work (I was naively hoping that this line might help Powershell "see" the assemblies.

Also of note, I *can* use the same API's in WSH scripts (using the "new ActiveXObject('Outlook.Application')" technique). Damn confusing.
Thursday, October 04, 2007 6:17:41 PM (Pacific Daylight Time, UTC-07:00)
Closing this out - I figured it out. I had my Powershell launching with run as Administrator privileges. Once this was disabled, all was well. Thanks for the help.
Thursday, October 04, 2007 6:47:58 PM (Pacific Daylight Time, UTC-07:00)
Hmm, that's a surprising cause. Were you launching it actually as the Administrator user (which might not have access to your profile?)
Name
E-mail
Home page

Comment (Some html is allowed: b, blockquote@cite, em, i, strike, strong, sub, super, u)  

Enter the code shown (prevents robots):