# Reading inbox on a shared mailbox on office365

**URL:** <https://forums.powershell.org/t/reading-inbox-on-a-shared-mailbox-on-office365/11411>\
**Category:** PowerShell Help\
**Created:** [October 4, 2018, 2:49am UTC](https://forums.powershell.org/t/reading-inbox-on-a-shared-mailbox-on-office365/11411 "2018-10-04T02:49:41Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![bdevogt](https://avatars.discourse-cdn.com/v4/letter/b/eada6e/32.png) [@bdevogt](https://forums.powershell.org/u/bdevogt)\
**Post date:** [October 4, 2018, 2:49am UTC](https://forums.powershell.org/t/reading-inbox-on-a-shared-mailbox-on-office365/11411/1 "2018-10-04T02:49:41Z")

</div>

Good morning all,

I’m trying to read the inbox of a shared mailbox.  
I found this script but cant find a way to change this to a shared mailbox because it doesn’t have a login.  
I’m using my own credentials (with rights on that mailbox)

Hope someone can point me in the right direction

```
# Written by Ben Penney https://sysadminben.wordpress.com

$mail='Email'
$password='Password'

# Set the path to your copy of EWS Managed API 
$dllpath = 'C:\Program Files\Microsoft\Exchange\Web Services\2.0\Microsoft.Exchange.WebServices.dll' 
# Load the Assemply 
$null = [Reflection.Assembly]::LoadFile($dllpath) 

# Create a new Exchange service object 
$service = new-object -TypeName Microsoft.Exchange.WebServices.Data.ExchangeService 

#These are your O365 credentials
$Service.Credentials = New-Object -TypeName Microsoft.Exchange.WebServices.Data.WebCredentials -ArgumentList ($mail,$password)

# this TestUrlCallback is purely a security check
$TestUrlCallback = {
    [CmdletBinding()]
    param ([string] $url)
    if ($url -eq 'https://autodiscover-s.outlook.com/autodiscover/autodiscover.xml') {$true} else {$false}
}
# Autodiscover using the mail address set above
$service.AutodiscoverUrl($mail,$TestUrlCallback)

# create Property Set to include body and header of email
$PropertySet = New-Object -TypeName Microsoft.Exchange.WebServices.Data.PropertySet -ArgumentList ([Microsoft.Exchange.WebServices.Data.BasePropertySet]::FirstClassProperties)

# set email body to text
$PropertySet.RequestedBodyType = [Microsoft.Exchange.WebServices.Data.BodyType]::Text

# Set how many emails we want to read at a time
$numOfEmailsToRead = 100

# Index to keep track of where we are up to. Set to 0 initially. 
$index = 0 

# Do/while loop for paging through the folder 
do 
{ 
    # Set what we want to retrieve from the folder. This will grab the first $pagesize emails
    $view = New-Object -TypeName Microsoft.Exchange.WebServices.Data.ItemView -ArgumentList ($numOfEmailsToRead,$index) 
    # Retrieve the data from the folder 
    $findResults = $service.FindItems([Microsoft.Exchange.WebServices.Data.WellKnownFolderName]::Inbox,$view) 
    foreach ($item in $findResults.Items)
    {
        # load the additional properties for the item
        $item.Load($propertySet)

        # Output the results
        "From: $($item.From.Name)"
        "Subject: $($item.Subject)"
        "Body: $($Item.Body.Text)"
        #"References: $($item.References)"
       # "InternetMessageID: $($item.InternetMessageID)"
       # 'InternetMessageHeaders:'
        # Display the headers - using a little foreach loop
       # $item.InternetMessageHeaders|foreach{"$($_.Name): $($_.Value)"} 
        '' 
    } 
    # Increment $index to next block of emails
    $index += $numOfEmailsToRead
} while ($findResults.MoreAvailable) # Do/While there are more emails to retrieve
```

---

<div class="post-metadata">

**Author:** ![bdevogt](https://avatars.discourse-cdn.com/v4/letter/b/eada6e/32.png) [@bdevogt](https://forums.powershell.org/u/bdevogt)\
**Post date:** [October 4, 2018, 4:29am UTC](https://forums.powershell.org/t/reading-inbox-on-a-shared-mailbox-on-office365/11411/2 "2018-10-04T04:29:21Z")

</div>

I solved the issue,

&nbsp;

You can set a password on a unlicensed shared mailbox user,

If you use this the script works

---

<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:34pm UTC](https://forums.powershell.org/t/reading-inbox-on-a-shared-mailbox-on-office365/11411/3 "2024-05-16T20:34:17Z")

</div>


