Quantcast
Channel: PowerShell.com – PowerShell Scripts, Tips, Forums, and Resources
Viewing all articles
Browse latest Browse all 6937

Can't get the contents of an inbox

$
0
0

Background: We have a public folder on Exchange 2010 that receives emails. An application runs every few seconds to check for new emails, then processes and removes them them from the folder. The processing time is pretty quick and doesn't take more than ten seconds for an individual email.

In the past, we've encountered problems where the application stops working for some reason. I wrote a Powershell monitor to run out every fifteen minutes and get a list of the emails in that folder. If an email is still in the folder fifteen minutes later, it sends out an alert to the support staff that something may be wrong.

We're migrating to Exchange 2013, and public folders don't exist. They've set up a regular inbox to receive and process the emails, and the new application (written in C#) is done and ready to go.

The problem is that I can't connect to this new inbox using Powershell. It would seem to be pretty simple, but isn't working. As I understand it, the inbox isn't owned by an account, but there is a service account (with its own inbox) that has full rights. I have also been granted full rights to the inbox and can access it through Outlook.

So, I've gone through a bunch of iterations for this. Here's the basic script. It doesn't return any errors, but it only gets the contents of my personal inbox. Does anyone have an idea of what's going on?

$email = "someinbox@domain.com"; ### Not my account
[Reflection.Assembly]::LoadFile("C:\Program Files\Microsoft\Exchange\Web Services\2.1\Microsoft.Exchange.WebServices.dll")
$s = New-Object Microsoft.Exchange.WebServices.Data.ExchangeService([Microsoft.Exchange.WebServices.Data.ExchangeVersion]::Exchange2013_SP1)
$s.Credentials = [System.Net.CredentialCache]::DefaultNetworkCredentials
$s.UseDefaultCredentials = $true
$s.AutodiscoverUrl($email)
$inbox = [Microsoft.Exchange.WebServices.Data.Folder]::Bind($s, [Microsoft.Exchange.WebServices.Data.WellKnownFolderName]::Inbox)
$inbox.FindItems(2) ### This only returns the contents of my personal mailbox

 


Viewing all articles
Browse latest Browse all 6937

Trending Articles