Submitted By: Kent Finkle

Retrieves the name of each folder and subfolder found in a Microsoft Outlook Inbox.

PowerShell
Edit|Remove
$comments = @' 
Script name: Visit-Subfolders.ps1 
Created on: Friday, August 17, 2007 
Author: Kent Finkle 
Purpose: How can I use Windows Powershell to 
Write a Script That Accesses All the Subfolders in My Outlook Inbox? 
'@ 
#----------------------------------------------------- 
function GetSubfolders($Parent) { 
    $folders = $Parent.Folders 
    foreach ($folder in $folders) { 
        $Subfolder = $Parent.Folders.Item($folder.Name) 
        Write-Host($folder.Name) 
        GetSubfolders($Subfolder) 
    } 
} 
#----------------------------------------------------- 
 
$olFolderInbox = 6 
 
$o = new-object -comobject outlook.application 
$n = $o.GetNamespace("MAPI") 

$f = $n.GetDefaultFolder($olFolderInbox) 
 
Write-Host($f.Name) 
 
GetSubfolders($f)