Displaying Email subjects from a particular folder

Welcome Forums General PowerShell Q&A Displaying Email subjects from a particular folder

This topic contains 5 replies, has 3 voices, and was last updated by

 
Participant
2 months, 3 weeks ago.

  • Author
    Posts
  • #113048

    Participant
    Points: 3
    Rank: Member

    Hi Team ,

    I want to list the email subjects from the Inbox folders . I have written  a code but it is taking me only to the folder level .Can you please tell me how to display the only email subjects from the folders .Please find the below code

    $outlook = new-object -com outlook.application;

    $ns = $outlook.GetNameSpace("MAPI");

    $inbox = $ns.GetDefaultFolder(6)

    $targetfolder = $inbox.Folders

    $targetfolder |select -Property Name

    If i execute the above code am getting the below folders that exists in my inbox .My queury is how to get only the email subjects that exists in  these folders .

    Name                                                                                                                                                          —-                                                                                                                                                              folder1                                                                                                                                                        folder2                                                                                                                                                        folder3                                                                                                                                                        folder4

  • #114018

    Participant
    Points: 1,124
    Helping Hand
    Rank: Community Hero

    @nikhileshwar – Did you get the solution for this ? if so please share it with us which will be helpful for others else please update this thread with latest update.

  • #118081

    Participant
    Points: 3
    Rank: Member

    Hi Prasoon

    $outlook = new-object -com outlook.application;
    $namespace = $outlook.GetNameSpace("MAPI");

    The below command will display the mail locations containing the inbox and sent items
    $namespace.folders|select -property folderpath

    If i want to display the inbox from the first mail location

    $namespace.folders.item(1).folders.item('Inbox')

    If i want to display the email subjects,receivedtime for the mails of the subfolder of this inbox you have to give

    $namespace.folders.item(1).folders.item('Inbox').folders.item('sub-folder').items|select -property subject,receivedtime

  • #118092

    Participant
    Points: 1,124
    Helping Hand
    Rank: Community Hero

    Thanks for sharing the solution. I will format it for others.

    $outlook = New-Object -ComObject Outlook.Application
    $Namespace = $Outlook.GetNameSpace("MAPI")
    #The below command will display the mail locations containing the inbox and sent items
    $Namespace.Folders | Select-Object -Property FolderPath
    #If i want to display the inbox from the first mail location
    $Namespace.Folders.Item(1).Folders.Item('Inbox')
    #If i want to display the email subjects,receivedtime for the mails of the subfolder of this inbox you have to give
    $Namespace.Folders.Item(1).Folders.Item('Inbox').Folders.Item('sub-folder').Items | Select-Object -Property Subject,ReceivedTme 
    
  • #119468

    Participant
    Points: 65
    Rank: Member

    Thanks for sharing the solution. I will format it for others.

    PowerShell
    9 lines

    1
    2
    3
    4
    5
    6
    7
    8
    9
    $outlook = New-Object ComObject Outlook.Application
    $Namespace = $Outlook.GetNameSpace("MAPI")
    #The below command will display the mail locations containing the inbox and sent items
    $Namespace.Folders | Select-Object Property FolderPath
    #If i want to display the inbox from the first mail location
    $Namespace.Folders.Item(1).Folders.Item('Inbox')
    #If i want to display the email subjects,receivedtime for the mails of the subfolder of this inbox you have to give
    $Namespace.Folders.Item(1).Folders.Item('Inbox').Folders.Item('sub-folder').Items | Select-Object Property Subject,ReceivedTme
    XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

    Mr. Prasoon,

    Thanks for sharing the script. However, it does not work, from the PowerShell ISE running as Administrator:

    New-Object : Retrieving the COM class factory for component with CLSID {0006F03A-0000-0000-C000-000000000046} failed due to the following error: 80080005 Server execution failed (Exception from HRESULT: 0x80080005 (CO_E_SERVER_EXEC_FAILURE)).
    At line:2 char:12
    + $outlook = New-Object -ComObject Outlook.Application
    + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo : ResourceUnavailable: (:) [New-Object], COMException
    + FullyQualifiedErrorId : NoCOMClassIdentified,Microsoft.PowerShell.Commands.NewObjectCommand

    You cannot call a method on a null-valued expression.
    At line:3 char:1
    + $Namespace = $Outlook.GetNameSpace("MAPI")
    + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo : InvalidOperation: (:) [], RuntimeException
    + FullyQualifiedErrorId : InvokeMethodOnNull

  • #119538

    Participant
    Points: 1,124
    Helping Hand
    Rank: Community Hero

    Start 32bit PowerShell or PowerShell ISE from C:\Windows\Syswow64\WindowsPowerShell\v1.0 . If this works, you MS office is 32 bit.

You must be logged in to reply to this topic.