here is a powershell script I wrote, it allows to search a foldername or to list the complete folders tree. Usage :
without parameter it will display all folders
PS>.\get-MailboxFolders.ps1 └@conserver └_Licences, codes etc. └2 Clic └Axter Ltd └Chili └Pérou
if you pass a parameter it will search for folder name containing that term and output the path
PS>.\get-MailboxFolders.ps1 201 The term *201* was found in : \\mailbox@domain.com\2015 \\mailbox@domain.com\archivage\2010 \\mailbox@domain.com\archivage\2011
you can search a specific account using the mailbox parameter
PS>.\get-MailboxFolders.ps1 -mailbox "infor" Account selected = ENT, Service Informatique └Archives └Boîte de réception
here is the script:
<# .Synopsis search outlook folders or display the folders tree .Description This script uses the outlook COM object. .Parameter folder Part of the folder's name to search for. If this parameter is not set the script will output the complete folders tree #> [CmdletBinding()] param( [Parameter(Position=0, Mandatory=$false,ValueFromPipeline = $true)] [System.String] $folder=$null, [Parameter(Position=1, Mandatory=$false)] [System.String] $mailbox=$null ) $output="" $find=@() function Get-MailboxFolder($folder,$prefix, $search=$null, $firstrun=$false){ if(($search -ne $null) -and ($folder.name -match $search)) { $script:find+=$folder.folderpath # if foldername match search term add it to the result } if($firstrun -eq $true){$script:output=$script:output+"$prefix$($_.name)`n"} # top level directories if ($folder.folders.count -gt 0 ){ # If there are subfolders if($firstrun -eq $false){ $script:output=$script:output+"$prefix$($folder.name)`n" } $prefix=" "+$prefix # preffix padding $folder.folders |sort -property name| %{ get-MailboxFolder $_ $prefix $search} #recursivity } # No subfolder if($folder.folders.count -eq 0 -and $firstrun -eq $false){$script:output=$script:output+"$prefix$($folder.name)`n"} } # Start outlook $o=New-Object -ComObject outlook.application $ns=$o.GetNamespace("MAPI") if($mailbox -ne $null){ $bal=$ns.Folders |?{$_.name -match $mailbox} } else{ $bal=$ns.Folders.Item(1) # select the default mail account // you can let $bal=$ns.Folders to search through all accounts } write-host "Account selected = $($bal.name)" $prefix="└" $i=1 $bal.folders|sort -property name |%{ $percent=$i*100/($bal.folders.count) write-progress -activity "Searching, please wait" -currentoperation "$($_.name)" -percentcomplete $percent get-MailboxFolder $_ $prefix $folder $true $i++ } if(($folder -ne $null) -and ($folder -ne "")){ # are we searching ? if ($find.count -eq 0) else } else{$script:output} # display tree $o.quit()