Powershell: Using Exchange Web Services (EWS) to Pull Data on a Mailbox You have Full Access Rights to



Needing to Know About Emails Coming to a Secondary Mailbox

Let’s say you have access to a mailbox–e.g. the helpdesk mailbox–via something like this EMS command

Now, let’s also assume you have it mounted in Outlook. Sure, you could have your ticketing system auto-ticket the emails, but let’s assume there’s a use-case where you want to know about the emails coming in.

Unfortunately, at least in Outlook 2007, you can’t apply notification/sound rules to a mailbox other than your primary. You could also try using something like ExtraOutlook, but my RAM says no.

Thankfully, you can use the EWS API via PowerShell to achieve this. It also allows you to use your normal credentials as long as that AD account has FullAccess to the mailbox in Exchange.

Powershell Script


  • Set $mailbox to the mailbox you want to fetch data from
  • You can supply a PS-style credential to the -creds parameter -or- let it prompt you. Use the AD-style account logon. There’s no real way to pass the current powershell token, so you will have to always enter the credential everytime you run the script.
  • $ewsDll should be set to your EWS dll path.
  • $sleepSeconds is used to delay the loop in this particular case where it checks for unread messages every X seconds
  • $wavNotifyFilePath (in this case referencing a .wav in the same directory as the script) is used as the notify sound in this cas

Obviously, you can explore the API and modify this to meet your needs. Once the main EWS assembly is loaded and the service/inbox objects are loaded, the access times aren’t bad (at least on my network). But, those initial calls are pretty heavy, so I’d keep that in mind, i.e. try to avoid having to load/reload the assembly/objects.

Leave a Reply

Your email address will not be published. Required fields are marked *