Read emails in a mailbox using an admin account

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

  • This topic has 0 replies, 1 voice, and was last updated 2 months ago by Hil.
Viewing 0 reply threads
  • Author
    Posts
    • #212943
      Hil
      Participant
      Topics: 28
      Replies: 39
      Points: 173
      Rank: Participant

      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:

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

       

      
      
      		
      	
Viewing 0 reply threads
  • You must be logged in to reply to this topic.