Submitted By: Kent Finkle

Creates a new Outlook folder named Scripts Received.

PowerShell
Edit|Remove
$comments = @'
Script name: Create-Folder.ps1
Created on: Wednesday, September 26, 2007
Author: Kent Finkle
Purpose: How can I use Windows Powershell to
Create a New Folder in Microsoft Outlook?
'@
#-----------------------------------------------------
function Release-Ref ($ref) {
([System.Runtime.InteropServices.Marshal]::ReleaseComObject(
[System.__ComObject]$ref) -gt 0)
[System.GC]::Collect()
[System.GC]::WaitForPendingFinalizers() 
}
#-----------------------------------------------------
$olFolderInbox = 6
 
$o = new-object -comobject outlook.application
$n = $o.GetNamespace("MAPI")

$f = $n.GetDefaultFolder($olFolderInbox)
 
$nf = $f.Folders.Add("Scripts Received")
 
$a = Release-Ref($nf)
$a = Release-Ref($f)
$a = Release-Ref($n)
$a = Release-Ref($o)