Friday, July 20, 2012

Creating an Equipment Mailbox with Powershell on Office 365

Recently, we needed some equipment mailboxes in our Office 365 environment for some development tasks using the Exchange Web Services. It seems like the guides that we found online were typically accurate but were frequently incomplete. They included some of the steps, but not enough to really get going fully. Below are the steps developed in order to create our equipment mailboxes.  The steps include several Powershell commands and should help provision the mailboxes from start to finish.

To start, you'll need to install and configure the Microsoft Online Services Module for Windows PowerShell . You can follow the instructions here to do so, it's easy enough.

Next we'll want to open the Microsoft Online Services Module for Windows Powershell program. It will launch like any other Powershell program. Once loaded, we need to give Powershell the credentials we'll be logging in to Office 365 as. These need to be for a user with Administrator privileges in your Office 365 domain. To do so, run the following command:
  • $credentials = Get-Credential
    • This will spawn a window asking for credentials, enter your Office 365 administrative credentials.

Once Powershell has your credentials, we need to log into the Office 365 servers using the credentials we just set and start our remote session. Use the command below to do so:
  • $session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri -Credential $credentials -Authentication Basic -AllowRedirection
    • This might take a few seconds to complete.

Now we need to import the Powershell commands, from the Microsoft servers to our local session.

Use the command below to do so.
  • $ImportResults = Import-PSSession $session

Now that we are properly staged up with our Session and we've imported the commands from the Microsoft Online Services, we can create the mailbox using the commands below:
  • New-Mailbox -Name EquipmentTest01 -DisplayName "Equipment Test-01" -Equipment
The command above will create a mailbox for the EquipmentTest01 user, with a display name of Equipment Test-01. The only thing that makes this command any different than normal create mailbox commands is just the -Equipment argument. You can add other arguments to this command as well, such as -OrganizationalUnit, or -Database to specify which mailbox store to use.

For our purposes, we need to give another user full access to the mailbox. So we used the following command to delegate the access to the user.
  • Add-MailboxPermission "Development User" -user "Equipment Test-01" -Accessright FullAccess
Once that was completed, we were done. There are more things around creation and delegation that can be performed, so I'll post all the documentation below.

Tuesday, July 17, 2012

Microsoft Lync Group Chat integration using C#

Recently we've been playing around with different ways of integrating and re-purposing Microsoft Lync and it's various server/client components into interesting applications with valuable and useful features. Over the past few weeks we've been working internally with the Lync Group Chat SDK, developing some prototypes for applications that could extend the functionality of the Group Chat rooms for other organizations.

For example, we are developing some applications that will monitor various services, such as email accounts or twitter feeds, and automically dispatch alerts into a Lync 2010 group chat room. 

Before we start with the code samples, I'll outline the system requirements below for packages to have installed.

Below is an example of a simple Group Chat task. This console application will log in to the Lync Server, log in to the Group Chat server, search for the chat room specified, join the chat room, send a sample chat message, and then disconnect from the room, chat server, and Lync server. This example provides a pretty comprehensive look at all the steps needed to perform simple to complex tasks on the Group Chat server using the Lync SDK and the Group Chat SDK.

For this application, we'll use the NDesk.Options library to parse our command line options to build up our message. Additionally, the configuration for the Group Chat settings is stored in an app.config file, which I'll outline below.

First, we build our Common class. This class holds some common variables which we'll use throughout the application, and some Group Chat specific functionality.

Some points about Common.cs:
  1. When building our UserEndpoint, we specify this application using the ClientPlatformSettings class, which for our console application, will give use a bit more ease of use and flexibility, rather than using the ServerPlatformSettings class.
  2. When joining a chat room, we first search for the room, and return a ChatRoomSnapshot. This snapshot provides us the information we need to then join the room using our Common.RoomJoinExisting method.

Next, we'll build up our actual program logic in Program.cs. This file holds 2 classes, our DispatchMessage class, and our Chat class. DispatchMethod is a simple object to hold the values that we'll be chatting into the chat room. This includes the message body, subject (if a story), if this message is an alert, and the name of the room we are looking to join. Our Chat class holds some various methods that we use at runtime, as well as our Main() program.

Some notes about Program.cs:

  1. After the NDesk.Options library parses the command line arguments, it populates the DispatchMessage class/object. Once this is complete, it runs through it's main try/catch block, which logs in to Lync, logs in to the Group Chat server, finds the room, and joins it.
  2. Once we have our session established, we move through our RoomChat method. This method reads from the DispatchMessage class/object and builds the actual chat message, then pushes it to the room.
  3. After the message has been posted, we leave room and disconnect our sessions.
In your app.config file, make sure to add the keys/values below to configure the environment settings for the application. We'll discuss what these keys mean below.

  <add key="OcsServer" value="######" />
  <add key="LookupServerUri" value="sip:###@###.###" />
  <add key="UserSipUri" value="sip:###@###.###" />
  <add key="Username" value="###@###.###" />
  <add key="Password" value="###" />
  • OcsServer
    • This is the server name to the Lync Front End Pool (probably something like '' or ''
  • LookupServerUri
    • This is the service account in SIP format that was setup with the Group Chat server. In our environment sip://ocschat@instant.local
  • UserSipUri
    • This is the account you'd like to send messages into the chat room as, in SIP format. This should be different than the LookupServerUri, and should be on the list of members for the chat room.
  • Username
    • The Active Directory user name that the user logs in to Lync as. Generally DOMAIN\username or or local.
  • Password
    • The users Active Directory password. Should be hashed or stored in some other fashion, but for our example, its plain-text in the file.
Once the program is built, run the .exe with the -? option to see the full help text, which will give you the parameters and syntax to run the program.

Using this core functionality we've wired up some protypes using Exchange Web Services, as well as Twitter's API. In Exchange, we monitor an inbox, when something arrives we parse out it's information, and send it to the appropriate chat room. Below, on the left you'll see the email drafted to the designated box, and on the right, the message as it appears as a story in the chat room.

For Twitter, we have the ability to watch user's Tweets, and track hashtags or other search queries. Below you'll see the tweet, as well as the message from our watched Twitter user in the chat room, complete with clickable links and some basic information.