Submitted By: Kent Finkle

Locates the first item in a Microsoft Outlook collection, then uses the GetNext method to access the next item in that collection.

PowerShell
Edit|Remove
$comments = @'
Script name: Use-GetNext.ps1
Created on: Thursday, August 23, 2007
Author: Kent Finkle
Purpose: How can I use Windows Powershell to
return the next object in the specified Outlook collection?
See http://msdn2.microsoft.com/en-us/library/aa220109(office.11).aspx
'@
$olFolderInbox = 6 
$o = new-object -comobject outlook.application
$n = $o.GetNamespace("MAPI")
$in = $n.GetDefaultFolder($olFolderInbox)
$folders = $in.Folders
$f = $folders.GetFirst()
While ($f -ne $null) {
    If ($f.Name -eq "MyPersonalEmails") {
        Write-Host("The folder was found.")
        break
    }
    $f = $folders.GetNext()
}