As a SharePoint developer and MSDN subscriber I was thrilled when Microsoft announced that it was offering a SharePoint Online subscription as part of the base benefits of an MSDN subscription. Being able to automate administrative tasks in SharePoint Online is a big help to those of us who don’t want to click through an interface every time we need to do something. To address this Microsoft has released the SharePoint Online Management Shell.
Getting a SharePoint Online environment
First, you need a SharePoint online environment. If you are an MSDN subscriber, you already have one included in your subscription. If not, the Developer Subscription costs $99 per year. There are also a number of Office 365 plans that include SharePoint online site. These come with a per-user monthly charge. There are also 30-day trials available.
Installing the SharePoint Online Management Shell
Setting up the PowerShell tools for SharePoint Online is easy and only takes a couple of minutes. You’ll need to be on PowerShell 3.0 first though. If you’re running Windows 8 or Server 2012 you’re in luck, it’s already there. If not it’s available for Windows 7 and Server 2008 and 2008R2 here.
Next, download the appropriate executable here, and execute it. That’s all there is to it.
Connecting to your environment
Once the install is complete, you’ll now have a new program installed called “SharePoint Online Management Shell”. You’ll need to launch this. Before interacting with your SharePoint environment you’ll need to connect to it, and that is done through the cmdlet connect-sposervice. This cmdlet takes a url and administrator credentials as parameters. There are two ways you can run this. Omitting the password will prompt you with a log in screen. To include the password, you’ll need to create a PSCredential object and pass that into the command:
$username = "admin@contoso.sharepoint.com" $password = "password" $cred = New-Object -TypeName System.Management.Automation.PSCredential -argumentlist $userName, $(convertto-securestring $Password -asplaintext -force) Connect-SPOService -Url http://contoso-admin.sharepoint.com -Credential $cred
(this snippet was taken straight from the Technet documentation)
It’s important to note that the url you pass in must be the url of the administrative site, the one that looks like this:
When running Connect-SPOService, the “no news is good news” rule applies, and if it succeeds you will just see a new command prompt on the next line.
Let’s do something!
All of the available commands in SharePoint Online Management Shell have to do with creating, deleting, or maintaining site collections. To create a new site collection run the following command:
New-SPOSite -Url https://contoso.sharepoint.com/sites/accounting -Owner admin@contoso.com -StorageQuota 100 -NoWait -ResourceQuota 50 -Template STS#0
(again, code sample lifted from technet)
The full list of SharePoint Online cmdlets can be found here.
How does it work?
Whenever you are working with tools that access remote environments, it is always illuminating to figure out the underlying technologies that make it work. In this case I launched Fiddler and ran a few commands. Here’s what I saw the first time:
That call to client.svc is the calling card of the SharePoint Client Side Object Model. It looks like the call to lists.asmx was simply to fetch a Form Digest so the CSOM call could use that to authenticate. Subsequent commands run from the shell do not make this call, so I am guessing the Form Digest is still valid in this case.
It’s interesting to note that the ability to manage site collections is a new feature in the CSOM for 2013. This functionality would not have been possible in 2010.
Limitations
On-Premise SharePoint PowerShell tools are quite powerful and can be used as a text-based SharePoint Manager to discover all sorts of things about your SharePoint environment. I routinely use PowerShell to look at things like list and view schemas, field definitions, web properties, and the like. Developers who are comfortable with using PowerShell in this fashion will find the array of commands available in SharePoint Online a little limiting. There is no way in this tool to manage objects below the site collection level. It appears this is strictly an administration tool.