Read emails in a mailbox using an admin account

Welcome Forums General PowerShell Q&A Read emails in a mailbox using an admin account

Viewing 0 reply threads
  • Author
    • #212973
      Topics: 34
      Replies: 46
      Points: 265
      Rank: Contributor

      I can use this script to read email in my own account. It works great. But if I specify an admin account to read emails in another mailbox It still reads the emails in my mailbox. How can I get it to read the emails in a different mailbox.

      Here is my code:

      $Userid="a4327"<br />$pass_secure = Get-Content "e:\hilario\cred_a910327.txt" | ConvertTo-SecureString<br />$credential = new-object -typename System.Management.Automation.PSCredential -argumentlist $Userid, $pass_secure<br />$password = $credential.GetNetworkCredential().password<br />$dllpath = "C:\Program Files\Microsoft\Exchange\Web Services\2.2\Microsoft.Exchange.WebServices.dll"<br />[void][Reflection.Assembly]::LoadFile($dllpath)<br />$service = new-object Microsoft.Exchange.WebServices.Data.ExchangeService<br />$Service.Credentials = New-Object Microsoft.Exchange.WebServices.Data.WebCredentials($Userid,$password)<br />$TestUrlCallback = {<br />param ([string] $url)<br />if ($url -eq "") {$true} else {$false}<br />}<br />$Sharedmail = "MessagingReports"<br />$service.AutodiscoverUrl($Sharedmail,$TestUrlCallback)<br />$PropertySet = New-Object Microsoft.Exchange.WebServices.Data.PropertySet([Microsoft.Exchange.WebServices.Data.BasePropertySet]::FirstClassProperties)<br />$PropertySet.RequestedBodyType = [Microsoft.Exchange.WebServices.Data.BodyType]::Text;<br />$numOfEmailsToRead = 5<br />$index = 0<br />$view = New-Object Microsoft.Exchange.WebServices.Data.ItemView($numOfEmailsToRead,$index)<br />$findResults = $service.FindItems([Microsoft.Exchange.WebServices.Data.WellKnownFolderName]::Inbox,$view)

Viewing 0 reply threads
  • The topic ‘Read emails in a mailbox using an admin account’ is closed to new replies.