Select Page
This entry has been published on 2016-11-10 and may be out of date.

Last Updated on 2016-11-10.

[:en]The following Powershell script code can be useful if you want to distribute an Outlook folder link to your web-based central email archiving solution:

#----------------------------------------------------- 
function Release-Ref ($ref) { 
([System.Runtime.InteropServices.Marshal]::ReleaseComObject( 
[System.__ComObject]$ref) -gt 0) 
[System.GC]::Collect() 
[System.GC]::WaitForPendingFinalizers()  
} 
#----------------------------------------------------- 
$olFolderInbox = 6 
$newFolderName = "-> Mail Archive"



#Optional: Check if user uses Outlook. Comment out if not necessary
if (!(Test-Path $env:localappdata\Microsoft\Outlook\*.*st))
{
    Write-Host "outlook has not been started or configured on client yet";
    exit
}  
$o = new-object -comobject outlook.application 
$n = $o.GetNamespace("MAPI") 
 
#Root = Parent of Inbox
$f = $n.GetDefaultFolder($olFolderInbox).Parent
  
$exists = $f.Folders | where-object { $_.name -eq $newFolderName }

if (!$exists)
{
    $nf = $f.Folders.Add($newFolderName) 
    $nf.WebViewURL = "http://mailarchive.mydomain.local"
    $nf.WebViewOn = "True"

    Write-Host "created"

    $a = Release-Ref($nf) 
}
else
{
    Write-Host "exists"
}
  
$a = Release-Ref($f) 
$a = Release-Ref($n) 
$a = Release-Ref($o)

Run it e.g. via GPO as user-based startup Powershell script.[:]