locked
Enumerates all email addresses RRS feed

  • Question

  • Hello

    Pls

    With Powershell ver.2:

    How do, to enumerates the email addresses in folder and sub-folder?

    Cls
    
    $Folder = "InBox"
    Add-Type -Assembly "Microsoft.Office.Interop.Outlook"
    $Outlook = New-Object -ComObject Outlook.Application
    $Namespace = $Outlook.GetNameSpace("MAPI")
    
    $NameSpace.Folders.Item(1)
    $Email = $NameSpace.Folders.Item(1).Folders.Item($Folder).Items
    $Email | Sort-Object SenderEmailAddress -Unique | FT SenderEmailAddress

    I get error:

    Impossible d'exécuter l'opération. Impossible de trouver un objet.
    At C:\Users\admin\AppData\Local\Temp\2638a18e-c81f-49d9-8a30-a1c6f31e46d4.ps1:9 char:1
    + $Email = $NameSpace.Folders.Item(1).Folders.Item($Folder).Items
    + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
        + CategoryInfo          : OperationStopped: (:) [], COMException
        + FullyQualifiedErrorId : System.Runtime.InteropServices.COMException
     
    
    
    
    I get only:
    SenderEmailAddress    
    ------------------    
    maccount@microsoft.com

    Thanks

    Arnold

    Saturday, December 19, 2020 10:16 AM

Answers

  • Hello

    the problem is resolved:

    Add-Type -Assembly "Microsoft.Office.Interop.Outlook"
    $Outlook = New-Object -ComObject Outlook.Application
    $Namespace = $Outlook.GetNameSpace("MAPI")
    
    $Espaces=$Namespace.folders
    
    #liste des profils/dossiers de contenu de messagerie
    write-output "*** LISTE DES PROFILS"
    foreach ($i in $Espaces){ echo $i.name}
    
    # Traitement de la racine du premier profil de messagerie
    $root=$Espaces[1]
    
    # Dossiers racine du premier profil
    #write-output "*** DOSSIERS DE LA RACINE"
    #$rootfolder=$root.folders
    #foreach($j in $rootfolder){echo $j.name}
    
    Function ListeFolder($root){
      $items=$root.items
      $itemsCount=$items.count
      $dossier=$root.fullFolderpath
      write-output "CONTENU DU dossier $dossier Items=$itemsCount LISTE DES ADRESSES d'expediteur de ce dossier"
    
      foreach($k in $items){
        $sender=$k.senderEmailAddress
        write-output $sender
        }  
    
      read-host -Prompt '***Validez par la touche ENTREE pour passer au dossier suivant***'
    
      $rootfolder=$root.folders
      foreach($j in $rootfolder){
        ListeFolder($j)
        }
      }
    
    ListeFolder($Root)

    Thanks

    Arnold

    • Marked as answer by arnold_ Sunday, December 20, 2020 9:33 PM
    Sunday, December 20, 2020 9:31 PM