Skip to main content

WebService to Find Room and Equipment Mailboxes in Exchange 2007

In Exchange 2007 one of the new features is resource mailboxes out of the box you have two types of these mailboxes Room mailbox and Equipment mailbox. I’m rewriting some Intranet Meeting availability pages at the moment to work with Exchange Web Services and one thing you can’t do in EWS is run a query to find all these type of objects in your Exchange Organization. There are also a bunch of new features such as being able to set the resource capacity (eg how many people a room can hold) and custom resource properties (eg what type of things are in the room such as a whiteboard, projector etc). As this information is all stored in Active Directory you need to use LDAP to query this information. Because this is the type of thing I might want to use in multiple applications I thought I’d put together a little WebService that I could consume that would query this information on behalf of the requesting application and return information about the resource mailboxes firstly their email address's so i could then use this in a GetUserAvailability EWS operation and also where they are located and the extra resource capacity and resource custom properties.

The code to do this is pretty simple it’s just your standard System.DirectoryServices searching code the Ldap filter I used was to filter on the msExchRecipientDisplayType property which seems to get set to 7 for a Room Mailbox and 8 for a Equipment Mailbox. The WebService needs the rights to make these queries into the directory which you will need to solve with Impersonation and Delegation on your server. Alternatively you can hard code the alternate credential in your code (or web.config file) this is what I’m actually doing so If left that code in and just commend it out.

You can have a bit more fun with this if you expand your code eg you can use one of the Exchange custom attributes to store the Ip ranges of the local Ip subnets that are in close proximity to the Meeting Room's physical location. And then grab the IP of the client at the Intranet and use this information to return the meeting rooms close to where the client is making the request from (this depends a lot on your local setup).

I’ve put a downloadable copy of the Webserivce code here the code itself looks like.

using System;
using System.Web;
using System.Web.Services;
using System.Xml;
using System.Web.Services.Protocols;
using System.DirectoryServices;
using System.IO;

[WebService(Namespace = "")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
public class Service : System.Web.Services.WebService
public Service () {

public XmlDocument FindRooms() {
return FindMailboxes(7);
public XmlDocument FindEquipment()
return FindMailboxes(8);

private XmlDocument FindMailboxes(int MailboxType) {
string sqSearchQuery = "";
string mtMailboxType = "";
case 7:
sqSearchQuery = "(&(&(&(mailNickname=*)(objectcategory=person)(objectclass=user)(msExchRecipientDisplayType=7))))";
mtMailboxType = "Room Mailbox";
case 8:
sqSearchQuery = "(&(&(&(mailNickname=*)(objectcategory=person)(objectclass=user)(msExchRecipientDisplayType=8))))";
mtMailboxType = "Equipment";
XmlDocument rdReturnResult = new XmlDocument();
StringWriter xsXmlString = new StringWriter();
XmlWriter xrXmlWritter = new XmlTextWriter(xsXmlString);
xrXmlWritter.WriteAttributeString("type", mtMailboxType);
SearchResultCollection srSearchResults;
string roRootDSE = dsDirectorySearcher.SearchRoot.Path;
//string roRootDSE = "LDAP://dcName/DC=e2007dev,DC=domain,DC=com,DC=au";
//DirectoryEntry deDirectoryEntry = new DirectoryEntry(roRootDSE,
@"e2007dev\username", "password");
DirectoryEntry deDirectoryEntry = new DirectoryEntry(roRootDSE);
DirectorySearcher dsDirectorySearcher = new DirectorySearcher(deDirectoryEntry);
dsDirectorySearcher.SearchScope = SearchScope.Subtree;
dsDirectorySearcher.Filter = sqSearchQuery;
srSearchResults = dsDirectorySearcher.FindAll();
foreach (SearchResult srSearchResult in srSearchResults)
WriteAttributeValue(xrXmlWritter, srSearchResult, "msExchResourceCapacity");
WriteAttributeValue(xrXmlWritter, srSearchResult, "msExchResourceDisplay");
WriteAttributeValue(xrXmlWritter, srSearchResult, "displayName");
WriteAttributeValue(xrXmlWritter, srSearchResult, "co");
WriteAttributeValue(xrXmlWritter, srSearchResult, "department");
WriteAttributeValue(xrXmlWritter, srSearchResult, "physicalDeliveryOfficeName");
WriteAttributeValue(xrXmlWritter, srSearchResult, "postalCode");
WriteAttributeValue(xrXmlWritter, srSearchResult, "postOfficeBox");
WriteAttributeValue(xrXmlWritter, srSearchResult, "st");
WriteAttributeValue(xrXmlWritter, srSearchResult, "streetAddress");
WriteAttributeValue(xrXmlWritter, srSearchResult, "telephoneNumber");
return rdReturnResult;
private void WriteAttributeValue(XmlWriter xrXmlWritter, SearchResult
srSearchResult, String atAttribute)
if (srSearchResult.Properties.Contains(atAttribute))

Popular posts from this blog

Downloading a shared file from Onedrive for business using Powershell

I thought I'd quickly share this script I came up with to download a file that was shared using One Drive for Business (which is SharePoint under the covers) with Powershell. The following script takes a OneDrive for business URL which would look like This script is pretty simple it uses the SharePoint CSOM (Client side object Model) which it loads in the first line. It uses the URI object to separate the host and relative URL which the CSOM requires and also the SharePointOnlineCredentials object to handle the Office365 SharePoint online authentication. The following script is a function that take the OneDrive URL, Credentials for Office365 and path you want to download the file to and downloads the file. eg to run the script you would use something like ./spdownload.ps1 '

Export calendar Items to a CSV file using EWS and Powershell

Somebody asked about this last week and while I have a lot of EWS scripts that do access the Calendar I didn't have a simple example that just exported a list of the Calendar events with relevant information to a CSV file so here it is. I've talked on this one before in this howto  but when you query the calendar folder using EWS you need to use a CalendarView which will expand any recurring appointments in a calendar. There are some limits when you use a calendarview in that you can only return a maximum of 2 years of appointments at a time and paging will limit the max number of items to 1000 per call. So if you have a calendar with a very large number of appointments you need to break your query into small date time blocks. In this example script I'm just grabbing the next 7 days of appointments if you want to query a longer period you need to adjust the following lines (keeping in mind what I just mentioned) #Define Date to Query $StartDate = (Get-Date) $EndDate

The MailboxConcurrency limit and using Batching in the Microsoft Graph API

If your getting an error such as Application is over its MailboxConcurrency limit while using the Microsoft Graph API this post may help you understand why. Background   The Mailbox  concurrency limit when your using the Graph API is 4 as per . This is evaluated for each app ID and mailbox combination so this means you can have different apps running under the same credentials and the poor behavior of one won't cause the other to be throttled. If you compared that to EWS you could have up to 27 concurrent connections but they are shared across all apps on a first come first served basis. Batching Batching in the Graph API is a way of combining multiple requests into a single HTTP request. Batching in the Exchange Mail API's EWS and MAPI has been around for a long time and its common, for email Apps to process large numbers of smaller items for a variety of reasons.  Batching in the Graph is limited to a m
All sample scripts and source code is provided by for illustrative purposes only. All examples are untested in different environments and therefore, I cannot guarantee or imply reliability, serviceability, or function of these programs.

All code contained herein is provided to you "AS IS" without any warranties of any kind. The implied warranties of non-infringement, merchantability and fitness for a particular purpose are expressly disclaimed.