powershelloutlookfavorites

[Powershell/MS Outlook]: Add folder to Favorites in Navigation Pane


I want to add a newly generated MAPI Folder to the Favorites Section in the Navigation Pane in Microsoft Outlook.

This is what i tried:

$Outlook = New-Object -ComObject Outlook.Application

$pst_name="c:\pathto\Test.pst"

$NameSpace = $Outlook.GetNameSpace("MAPI")
$NameSpace.AddStore($pst_name)

$olFolder = $NameSpace.Folders.GetLast()
$olNewFolder = $olFolder.Folders.Add("NewFolder")

$olNewFolder.AddToFavorites()

The script runs without erros, and the 'NewFolder' is generated. However the last line does not sho any effect, and the Folder is not found in the favorites section.

My configuration:

Any idea?

Thanks, BerndGit


Solution

  • Ok. Found already the answer - Faster then expected. Solution is based on: https://serverfault.com/questions/1044078/get-list-of-outlook-favorite-item-via-powershell and Outlook. Add folder to favorites group

    $Outlook = New-Object -ComObject Outlook.Application
    
    $pst_name="C:\pathto\Test1123.pst"
    
    $NameSpace = $Outlook.GetNameSpace("MAPI")
    $NameSpace.AddStore($pst_name)
    
    $olFolder = $NameSpace.Folders.GetLast()
    $olNewFolder = $olFolder.Folders.Add("NewFolder121")
    
    $ex = $Outlook.Application.ActiveExplorer()
    $mm = $ex.NavigationPane.Modules.GetNavigationModule(0)
    $favorites = $mm.NavigationGroups.GetDefaultNavigationGroup(4)
    $favorites.NavigationFolders.Add($olNewFolder)