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

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 

June 24th, 2015 2:07am

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

Free Windows Admin Tool Kit Click here and download it now
June 24th, 2015 9:57pm

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

June 24th, 2015 9:57pm

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
Free Windows Admin Tool Kit Click here and download it now
June 25th, 2015 3:16am

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
June 25th, 2015 3:16am

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

Free Windows Admin Tool Kit Click here and download it now
June 27th, 2015 3:41am

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

June 28th, 2015 9:08pm

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 2 hours 36 minutes ago
Free Windows Admin Tool Kit Click here and download it now
June 29th, 2015 1:07am

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

  

June 29th, 2015 3:55am

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 2 hours 36 minutes ago
  • Unmarked as answer by manidurai 2 hours 33 minutes ago
Free Windows Admin Tool Kit Click here and download it now
June 29th, 2015 7:52am

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

June 29th, 2015 11:39pm

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 2 hours 37 minutes ago
Free Windows Admin Tool Kit Click here and download it now
June 30th, 2015 3:36am

Hi Glen

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

Thanks

Manidurai

June 30th, 2015 10:39am

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics