List emails in an Office 365 mailbox

Hi, I could use this script to get the emails in my mailbox, But do I get the messages in any mailbox. How can i specify the alias or smtp address of the mailbox to get the emails within the mailbox

#Load the API DLL
$dllpath = "C:\Program Files\Microsoft\Exchange\Web Services\1.1\Microsoft.Exchange.WebServices.dll"
[void][Reflection.Assembly]::LoadFile($dllpath)

#Create a new service object
$service = new-object Microsoft.Exchange.WebServices.Data.ExchangeService([Microsoft.Exchange.WebServices.Data.ExchangeVersion]::Exchange2007_SP1)

# Fancy Way to Check the user and dynamically assign the Autodiscover URL
$windowsIdentity = [System.Security.Principal.WindowsIdentity]::GetCurrent()
$sidbind = "LDAP://"
$aceuser = [ADSI]$sidbind
$service.AutodiscoverUrl($aceuser.mail.ToString())

#Do some stuff

$inbox = [Microsoft.Exchange.WebServices.Data.Folder]::Bind($service, [Microsoft.Exchange.WebServices.Data.WellKnownFolderName]::Inbox)
$viewCount = 60
$view = New-Object Microsoft.Exchange.WebServices.Data.ItemView($viewCount)
$findResults = $service.FindItems([Microsoft.Exchange.WebServices.Data.WellKnownFolderName]::Inbox,$view)


$i = 0
#$cpsFound = 0
while ($i -le ($viewCount - 1))
{
$currdate = Get-Date
    #$findResults.Items[$i].Id |fl *
    if($findResults.Items[$i].DateTimeSent.ToShortDateString() -eq $currdate.ToShortDateString())
    {
        if($findResults.Items[$i].Subject.Contains("STRING_UR_LOOKING_4") -eq $True)
        {
         
        "Subject : " + $findResults.Items[$i].Subject

        $EmailItemID = $findResults.Items[$i].Id
        $currEmailItem = [Microsoft.Exchange.WebServices.Data.Item]::Bind($service,$EmailItemID)   
        $currSubject = $findResults.Items[$i].Subject
        $myParseCmd = $currSubject.Split("|")
       
        #$currEmailItem.Sender.Address

        } 
        }    
        
     # Increment the while loop 
        $i +=1
    } 

This script was taken from Export Email Header Information via PowerShell

This is not a PS issue. It is a permissions issue in O365/AAD.

Unless you are a global admin in O365/AAD or Exchange Admin or have been granted the Exchange Application Impersonation role rights, you cannot look into another users mailbox. Looking into, acting on another user mailbox requires delegated right directly or via Exchange AppImpersonation.

Imagine the security implications / ramifications if any random user / dev to just pop open anyone mailbox. Not a good thing.

MS provides many docs on Exchange AppImpersonation.

ApplicationImpersonation role: Exchange 2013 Help | Microsoft Docs
Impersonation and EWS in Exchange | Microsoft Docs
The importance of EWS Impersonation while using an application account. | Microsoft Docs

I am already an admin and have full rights to all user mailboxes.

Any ideas on the correct syntax?

I was able to get autodiscover to work, but $inbox returns the Inbox of the admin account.
How can i get it to return the Inbox of the mobileprint shared mailbox.
Any ideas?

[Reflection.Assembly]::LoadFile("C:\Program Files\Microsoft\Exchange\Web Services\2.0\Microsoft.Exchange.WebServices.dll")
$s = New-Object Microsoft.Exchange.WebServices.Data.ExchangeService
$AdminName = "a1234@abcdef.com"
$Pass = Get-Content "cred_.txt" | ConvertTo-SecureString
$s.Credentials = New-Object Net.NetworkCredential($AdminName , $Pass)
$s.AutodiscoverUrl("mobileprint@abcdef.com", {$true})
$inbox = [Microsoft.Exchange.WebServices.Data.Folder]::Bind($s,[Microsoft.Exchange.WebServices.Data.WellKnownFolderName]::Inbox)
$inbox