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