Guest Post: Managing Office 365 with PowerShell

By Thomas Lee – PowerShell MVP

imageimageThomas is a UK IT Pro, with over 40 years’ experience in the IT field. He’s presently a PowerShell MCP and is very busy doing writing, consulting and training around some of the key Microsoft technologies including PowerShell, Lync and Windows Server/client. In his spare time, he lives in a small cottage with wife, daughter, a nice wine cellar and a large collection of Grateful Dead live recordings.

Introduction

Office 365 is Microsoft’s Cloud Software-As-A-Service (SAAS) offering that provides Office 2010, Exchange 2010, SharePoint 2010, and Lync 2010. There are a variety of plans offering different aspects of these packages. Licensing and costs vary depending on what plan you take – and happily for Office 365 customers, Microsoft has just announced price reductions in the pricing! For more detailed information about Office 365 itself, see https://onlinehelp.microsoft.com/en-us/office365-enterprises/default.aspx.

One important aspect of Office 365, for IT Pros especially, is how you manage the suite. You can do the basic administration of Office 365 using a browser based GUI. The GUI is good, although doing larger scale management tasks can get tedious (and are error prone). Help is at hand in the form of a set of Windows PowerShell cmdlets you can use to perform a variety of administrative tasks with Office 365.

Additionally, if you are using Exchange within Office 365, you can perform Exchange management using PowerShell. For this, you simply use PowerShell V2’s remoting capability to remote into your Exchange server and then use implicit remoting to access a subset of the Exchange PowerShell cmdlets, as I explain in more detail later in this article. At present, unfortunately, there are no cmdlets available, directly or indirectly, for the SharePoint and Lync components of Office 365.

Office 365 Cmdlets

In order to use the Office 365 cmdlets, you must first download and install Microsoft Online Services Sign-in Assistant. Then you need to download and install the Microsoft Online Services module. Both of these software components come in both a 32-bit and a 64-bit version – choose the one that matches your OS. You can get these components via the online help page at: https://onlinehelp.microsoft.com/office365-enterprises/hh124998.aspx

Once you have the cmdlets installed, using them is a breeze, assuming you know PowerShell! Like any module, you must first import it into your PowerShell runspace, using the Import-Module cmdlet. Of course, for those of you using V3, importing the module is automatically done by PowerShell. Finally, in order to use the cmdlets, you have to authenticate yourself to Office 365 using the Connect-MsolService cmdlet. You can see this here:

clip_image002

Sadly, the limitations of this blog post does not allow me the space to delve into all these cmdlets in detail. But they allow you to carry out the following administrative activities:

· Manage users

· Manage group and role membership

· Manage service principals

· Manage domains

· Manage single sign-on

· Manage subscriptions and licenses

· Manage company information and service

You can click on the links above to get more information about each of these administrative activities, or navigate to https://onlinehelp.microsoft.com/en-us/office365-enterprises/hh125002.aspx.

Using PowerShell to Manage Exchange OnLine

You can manage Exchange On-Line, as noted earlier, by using the Exchange cmdlets in conjunction with PowerShell remoting (a key feature of Windows PowerShell V2!). To access the Exchange cmdlets, you just connect to the Exchange server, and use the implicit remoting capability of PowerShell to import the cmdlets into your runspace then use them as proxies, like this:

# First Get credential for site
$cred = Get-Credential
tfl@yourOffice365domain.onmicrosoft.com

# Next create a new PS Session
# Use a hash table to setup parameters to new-pssession
$Office365 = @{ ConfigurationName = "Microsoft.Exchange"
Connectionuri = "
Https://ps.outlook.com/powershell"

Credential = $cred365
Authentication = "Basic"
AllowRedirection = $true}

$s = New-PsSession @Office365

# Note: you see the session being redirected to your site
# Next Import the remote session
$Results = Import-PsSession $s

After doing this, you have direct access to the Exchange cmdlets that ship with Exchange 2010. It’s important to note you do not have access to ALL the cmdlets. The Exchange OnLine service’s multi-tenant architecture enables Microsoft, the hoster for Office 365, to customize what cmdlets you are able to use (and what properties of those cmdlets you can use). As of now, you can access just 234 cmdlets of the over 600 cmdlets that ship with Exchange 2010. For some more detail on using these cmdlets, see: https://tfl09.blogspot.co.uk/2011/04/getting-started-with-office-365.html

Getting Trained on PowerShell

As you can see, automation of Office 365 administration, both for the current version and future iterations, is increasingly reliant on PowerShell. As an IT Pro, learning PowerShell is something you really need to do sooner rather than later. But you probably know that!

For Microsoft partners that are reselling Office 365, using these PowerShell cmdlets is becoming a fundamental skill to enable you to manage your various clients’ Office 365 subscriptions in a cost efficient way. And for both partners and Office 365 users, you are almost certainly going to want to script many aspects of your management of use of Office 365, especially if you are using a hybrid (part cloud, part on premise) Office 365 architecture.

There are a variety of ways to learn more about PowerShell – as I blogged last month. You can go on the official Microsoft 5-Day PowerShell introduction, for example. At the risk of repeating myself, a great way to get up to speed quickly is to come on one of my PowerShell weekend PowerCamps - the next PowerCamp will be on April 21/22 and will be held at Microsoft’s Cardinal Place offices in London. For more information about this event, and to sign up, see https://tfl09.blogspot.co.uk/2012/01/powershell-powercamp-weekendlondonapril.html. The event will be a lot of fun, you’ll go home knowing tons more, and with a bunch of goodies and, no doubt, a head ready to explode!

Office 365 is a pretty awesome product for both small/medium businesses as an alternative to running servers on premise and for large business running a hybrid (part Cloud, part on-premise) environment. So no matter how you are going to be using Office 365, there’s good PowerShell support. Just a few more cmdlets to use, and the ability to master PowerShell’s remoting capability. Enjoy Office 365!