Automate SharePoint Online Administration with Azure Runbooks

Azure Runbooks are part of Azure Automation, they are written in PowerShell and run in Azure. Azure Runbooks are typically used to automate a process done by an administrator. They can accomplish anything that you can do in PowerShell. And you can automate tasks done inside or outside of Azure, in my case I will be building out an example using SharePoint Online.

So basically Azure Automation provides a central location where you can stage, configure and run your systems administration tasks. It can be very beneficial to move away from administrators running scripts on their individual workstations and to a solution like Azure Runbooks where everyone on the team could have access to the scripts, view the details and execution history, and so forth.

In my example I will be creating a PowerShell script to create a OneDrive site. Normally OneDrive sites are provisioned when the Office 365 license has been assigned to a user, but you may have the need to manually create a site if this provisioning process hangs or errors out. So this is one example, but you can really use this pattern for any other SharePoint online administration task you may perform using PowerShell.

Prerequisties: 1) SharePoint Online Management Shell – You will need this install on your development workstation. Later in this procedure we will be importing this module into our Azure Automation environment.
2) An azure account. You may have access to Azure through your MSDN subscription, through a company account, a free trial, or pay as you go as an individual.

Alright, lets get started. Our first step is to create an Azure Automation account if you don’t already have one.

Create an Azure Automation account In the azure portal, click ‘more services’ and then type in ‘automation accounts’.

Then click the ‘Create Automation Accounts’ button.

Next, fill in your account detail. Supply a name, select a subscription, and create a resource group.

After your automation group has finished its deployment you will see the automation account blade.

Import the SharePoint Online Integration Module. For my example I’m going to need the cmdlets in the SharePoint Online Management module. In order to use that module in an Azure Runbook, I need to load that module into my Azure so my automation account can call it.

First, open windows explorer to c:\program files\Sharepoint online management shell\. Right click the ‘Microsoft.Online.SharePoint.PowerShell’ folder and select send to zipped folder. (save to the desktop if prompted)

Back in the azure portal, under your automation account blade. Click the ‘Modules’ link under the shared resources section.

Then click the ‘Add a module’ button.

At the prompt, click the folder icon and navigate to the zip file you saved.

Click the ‘ok’ button to continue.

When we’re done, the module will be shown as available in the modules list.

Create A Credential. Next, we will create a credential to store the account information that will be used to access our SharePoint tenant. This account should at least be in the SharePoint administrator role in order to create OneDrive sites.

Click the Credentials link. And then the add credential button.

Complete the new credential form and then click the ‘Create’ button to proceed.

Create the Runbook. Ok now we can create our actual Runbook. Click the ‘Runbooks’ button, then the ‘Add Runbook’ button.

Then click the ‘Quick Create’ link.

I will give my runbook a name and then select ‘PowerShell’ as the runbook type.

Click the ‘Create’ button to proceed.

Here is the code for my Runbook. I’m creating a parameter to pass in the email of the user we would like to create the OneDrive site for, I’m pulling in the credential we previously configured. Then I connect to my tenant, make the request, and then disconnect.

Click the save button and then the publish button, confirming that you want to publish the Runbook.

You can then test the runbook by clicking the ‘Start’ button.

Supply a user email for the parameter and click the ‘ok’ button to proceed.

When the job status updates to completed you can click the ‘all logs’ button.

And the log then displays the output from our run:

Conclusion. The Azure Runbooks feature has been around for a while and most organizations have recognized that PowerShell is a very necessary automation tool. As we saw from this demo there was a fair number of steps to set up the runbooks environment, but once everything is set up Runbooks can be a very useful way to run and manage their automation scripts.

With this particular PowerShell script we’ve taken a support process that would have required the local installation of SharePoint Online management shell, and SharePoint administrator privilege and knowledge of PowerShell published it as a runbook in Azure. To run the finished Runbook you just need to click the play button and supply an email address, so this could be something that could be delegated to more front line support staff instead of requiring a skilled SharePoint administrator.

Runbooks can be kicked off on a schedule or on demand, so it’s a fairly flexible model.

Hopefully you find this post informative and it gives you some ideas about how you may wish to use Runbooks in your own organization.

Getting Started with SharePoint online Automation Using Azure Runbook
My first PowerShell Runbook
Credential assets in Azure Automation