Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I need to query my inbox with powershell recursivly for all "undelivered email returner"...

I have problems with the recursive part...

This is what I got:

$outlook = new-object -com Outlook.Application
$ns = $olApp.GetNamespace("MAPI")
$mb = $namespace.Folders | ?{$_.name -match "mailbox"}   
$folder1 = $mb.Folders | ?{$_.name -match "folder1"}   
$folder1.Folders | %{$_.name}  

$folder1.items | foreach {
if($_.subject -match "undelivered") {...}
}

This is what I got ... but I have some sort of problem with the recursive part in scripting..

any help would be greate...

thanks

share|improve this question
add comment

1 Answer

Here's a short script that should help you out. It walks through all folders in a mailbox and outputs their path. You can update the work done in the recursive section to check the items in each folder as it passes through them.

$outlook = New-Object -Com Outlook.Application
$mapi = $outlook.GetNamespace('MAPI')
$mailboxRoot = $mapi.GetDefaultFolder([Microsoft.Office.Interop.Outlook.OlDefaultFolders]::olFolderInbox).Parent
$walkFolderScriptBlock = {
    param(
    	$currentFolder
    )
    foreach ($item in $currentFolder.Folders) {
    	$item.FolderPath
    	& $walkFolderScriptBlock $item
    }
}
& $walkFolderScriptBlock $mailboxRoot
share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.