Wednesday, May 16, 2012

Add Categories to Outlook

So I wanted to take a list of categories from our CRM solution and put them Outlook so I can track how many emails and meetings I am sending/hosting for each project. I exported the CRM categories to a txt file and then ran this script.

cls
$cats = Get-Content c:\Temp\categories.txt
foreach ($cat in $cats)
{
$cat
Add-type -assembly "Microsoft.Office.Interop.Outlook" | out-null
$olFolders = "Microsoft.Office.Interop.Outlook.OlDefaultFolders" -as [type]
$outlook = new-object -comobject outlook.application
$namespace = $outlook.GetNameSpace("MAPI")
$folder = $namespace.getDefaultFolder($olFolders::olFolderCalendar)
$new=$folder.Session.Categories
$new.Add($cat)
}