Saturday, 31 October 2020

Powershell Script - Outlook Folder & eMail list

 This script to can be used to get the list of folders in Inbox and list the eMails. 


clear

$outlook = new-object -com Outlook.Application

$Namespace = $Outlook.GetNameSpace("MAPI")

$mb=$outlook.session.folders|?{$_.name -like "**MailBox***"}

$inbox = ($mb.folders |?{$_.name -eq "Inbox"}).folders

$Namespace.Folders.Item(1).folders.Item('Inbox').items | select -Property subject, receivedtime

  foreach ($f in $inbox ) {

    Write-Host  $f.name

     Write-Host  "----------------------------"

   if ($f.name -eq "Folder1" -Or $f.name -eq ".Folder2") {

       $Namespace.Folders.Item(1).Folders.Item('Inbox').Folders.Item($f.Name).Items |  sort receivedtime -desc |  %{echo   $_.subject }

   } #End If

         } #End ForEach