locked
How to read Message body from Exchange server massage store using power shell query RRS feed

  • Question

  • Hi

    I want to read all mailbox user send message body using power shell query ,if anybody know about that pls help me ....

    thanks 

    manidurai 

    Wednesday, June 24, 2015 6:04 AM

Answers

  • There are two options for authentication the first is having Full Access granted to the Mailbox via Add-MailboxPermissions . Note your Administrative rights don't mater when in comes to Mailbox access they only rights they give you is the ability to add and remove rights to a mailbox.

    The other option you can use to access a Mailbox is grant impersonation rights to the account your using to connect see https://technet.microsoft.com/en-AU/library/dd776119(v=exchg.150).aspx

    If you use the impersonation option you'll need to modify the script to use impersonation the lines are already in the script but commented out eg enable this line by removing the # in front

    $service.ImpersonatedUserId = new-object Microsoft.Exchange.WebServices.Data.ImpersonatedUserId([Microsoft.Exchange.WebServices.Data.ConnectingIdType]::SmtpAddress, $MailboxName) 
    Cheers
    Glen

    • Marked as answer by manidurai Wednesday, July 1, 2015 4:50 AM
    Monday, June 29, 2015 1:07 AM
  • You need to enumerate the Items in the folder you want to read them from and then load the body property eg for the Inbox

    # Bind to the Inbox Folder
    $folderid= new-object Microsoft.Exchange.WebServices.Data.FolderId([Microsoft.Exchange.WebServices.Data.WellKnownFolderName]::Inbox,$MailboxName)   
    $Inbox = [Microsoft.Exchange.WebServices.Data.Folder]::Bind($service,$folderid)
    $psPropset= new-object Microsoft.Exchange.WebServices.Data.PropertySet([Microsoft.Exchange.WebServices.Data.BasePropertySet]::FirstClassProperties)  
    #Define ItemView to retrive just 1000 Items    
    $ivItemView =  New-Object Microsoft.Exchange.WebServices.Data.ItemView(1000)    
    $fiItems = $null    
    do{    
        $fiItems = $service.FindItems($Inbox.Id,$ivItemView)    
        [Void]$service.LoadPropertiesForItems($fiItems,$psPropset)  
        foreach($Item in $fiItems.Items){      
    			Write-Host ($Item.Body.Text)          
        }    
        $ivItemView.Offset += $fiItems.Items.Count    
    }while($fiItems.MoreAvailable -eq $true) 
    Cheers
    Glen

    • Marked as answer by manidurai Wednesday, July 1, 2015 4:50 AM
    Tuesday, June 30, 2015 3:36 AM

All replies

  • The best place to start with is read the forum guide https://social.technet.microsoft.com/Forums/office/en-US/77c07b69-eea6-43ab-9225-4b384cecfc9d/exchange-development-forum-guide-read-before-posting?forum=exchangesvrdevelopment

    And then try to give some context to what your trying to do in your question and what code your trying to use eg post the code your using. Eg if you just want to search for text within a Message body for legal discovery the I would suggest you use Search-Mailbox https://technet.microsoft.com/en-us/library/ff459253(v=exchg.150).aspx .

    Cheers
    Glen

    Thursday, June 25, 2015 1:53 AM
  • Hi glen 
     
      i want to get reports based on all users mail message body. then do u have any direct  powershell query to read message body of all users mail and also i need powershell query to get  unread messages count for all users .. 


    thanks
    Manidurai
    Thursday, June 25, 2015 7:12 AM
  • Hi Glen

    i saw your blogs for unread message count(http://gsexdev.blogspot.com.au/2012/10/reporting-on-item-age-count-and-size-in.html) ,then it's working perfectly but it's  need full access permission to get unread message count , my need is get unread count without full access privilege then my account have Enterprise administrator and organization management but no luck it's required only full access privilege  for all mailbox users. pls help me..

    Thanks

    Manidurai

    Saturday, June 27, 2015 7:38 AM
  • There are two options for authentication the first is having Full Access granted to the Mailbox via Add-MailboxPermissions . Note your Administrative rights don't mater when in comes to Mailbox access they only rights they give you is the ability to add and remove rights to a mailbox.

    The other option you can use to access a Mailbox is grant impersonation rights to the account your using to connect see https://technet.microsoft.com/en-AU/library/dd776119(v=exchg.150).aspx

    If you use the impersonation option you'll need to modify the script to use impersonation the lines are already in the script but commented out eg enable this line by removing the # in front

    $service.ImpersonatedUserId = new-object Microsoft.Exchange.WebServices.Data.ImpersonatedUserId([Microsoft.Exchange.WebServices.Data.ConnectingIdType]::SmtpAddress, $MailboxName) 
    Cheers
    Glen

    • Marked as answer by manidurai Wednesday, July 1, 2015 4:50 AM
    Monday, June 29, 2015 1:07 AM
  • Hi Glen

    Thanks a lot glen, unread message count with impersonation option is working perfectly ,then i actually assigned impersonation role via following command

    New-ManagementRoleAssignment –Name:impersonationAssignment –Role:ApplicationImpersonation –User:<username>

    do you have any Powershell  scricpt for read all users message body using EWS, Pls help me   

    Thanks

    Manidurai

      

    • Marked as answer by manidurai Wednesday, July 1, 2015 4:51 AM
    • Unmarked as answer by manidurai Wednesday, July 1, 2015 4:53 AM
    Monday, June 29, 2015 7:52 AM
  • You need to enumerate the Items in the folder you want to read them from and then load the body property eg for the Inbox

    # Bind to the Inbox Folder
    $folderid= new-object Microsoft.Exchange.WebServices.Data.FolderId([Microsoft.Exchange.WebServices.Data.WellKnownFolderName]::Inbox,$MailboxName)   
    $Inbox = [Microsoft.Exchange.WebServices.Data.Folder]::Bind($service,$folderid)
    $psPropset= new-object Microsoft.Exchange.WebServices.Data.PropertySet([Microsoft.Exchange.WebServices.Data.BasePropertySet]::FirstClassProperties)  
    #Define ItemView to retrive just 1000 Items    
    $ivItemView =  New-Object Microsoft.Exchange.WebServices.Data.ItemView(1000)    
    $fiItems = $null    
    do{    
        $fiItems = $service.FindItems($Inbox.Id,$ivItemView)    
        [Void]$service.LoadPropertiesForItems($fiItems,$psPropset)  
        foreach($Item in $fiItems.Items){      
    			Write-Host ($Item.Body.Text)          
        }    
        $ivItemView.Offset += $fiItems.Items.Count    
    }while($fiItems.MoreAvailable -eq $true) 
    Cheers
    Glen

    • Marked as answer by manidurai Wednesday, July 1, 2015 4:50 AM
    Tuesday, June 30, 2015 3:36 AM
  • Hi Glen

    Thanks a lot ,your Message body script is working Perfectly ...

    Thanks

    Manidurai

    Tuesday, June 30, 2015 2:37 PM