# Read emails in a mailbox using an admin account

**URL:** <https://forums.powershell.org/t/read-emails-in-a-mailbox-using-an-admin-account/14044>\
**Category:** PowerShell Help\
**Created:** [March 27, 2020, 12:35pm UTC](https://forums.powershell.org/t/read-emails-in-a-mailbox-using-an-admin-account/14044 "2020-03-27T12:35:01Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![hdsouza](https://avatars.discourse-cdn.com/v4/letter/h/977dab/32.png) [@hdsouza](https://forums.powershell.org/u/hdsouza)\
**Post date:** [March 27, 2020, 12:35pm UTC](https://forums.powershell.org/t/read-emails-in-a-mailbox-using-an-admin-account/14044/1 "2020-03-27T12:35:01Z")

</div>

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>`
```

&nbsp;

```

```

---

<div class="post-metadata">

**Author:** ![dotnVo](https://avatars.discourse-cdn.com/v4/letter/d/4af34b/32.png) [@dotnVo](https://forums.powershell.org/u/dotnVo)\
**Post date:** [May 16, 2024, 8:30pm UTC](https://forums.powershell.org/t/read-emails-in-a-mailbox-using-an-admin-account/14044/2 "2024-05-16T20:30:02Z")

</div>


