SharePoint Automation using Azure Automation service


Recently, I had a situation where I wanted to run few PowerShell scripts against my SharePoint Online environment. but couldn't because the scripts execution was blocked on my system by the admin. To find a workaround, I started exploring other options to execute my PowerShell scripts, then I came across the Azure Automation Service which not only allows us to execute the scripts on cloud, but there's more we can do with it like automating all of the SharePoint administrative tasks. In this article we will learn about the Azure Automation service and an example on how we can leverage it for performing SharePoint administration tasks.

Azure Automation Service

Azure Automation is a cloud-based automation and configuration service which allows you to automate, manage and configure you environments. The service opens many opportunities to the admins to perform and automate their repetitive cloud management tasks for the Azure and non Azure environments like Office 365, SharePoint etc. For example, In SharePoint, you may need to automate the site provision solution, configuring site Configurations like Branding etc.

Azure Automation capabilities

SharePoint Online Automation using Azure Automation

In this example, we will learn how to create and use Azure Automation service to run an PowerShell script which will list all SharePoint online sites available in a tenant.

Create Azure Automation Account

  1. Login to Azure Portal.
  2. Click on Create a resource link.
  3. Search the marketplace for Automation service.
  4. Click on Create button to create an Automation account.
  5. Fill in the details and click on Create button. It will take few minutes to create an account. You can take a look at progress under notifications menu. 

Import SharePoint Online PowerShell module

In order to work with SharePoint cmdlets in PowerShell we will need to import the SharePoint Online module for Windows PowerShell. 
  1. Navigate to Automation resource and click on Modules gallery option under left navigation menu.
  2. Search and import Microsoft.Online.SharePoint.PowerShell module. It may take few minutes to import the module.

Import sample script from Runbooks gallery

  1. Navigate to Runbooks gallery by clicking on Runbooks link under left navigation menu and then clicking on Browse gallery option under top command bar.
  2. Search and import Connect to SharePoint Online and display all provisioned site collections script.
  3. Publish the script once it is imported successfully.

Create PS Credential parameter

Once you edit the script, you would have noticed it takes 2 arguments SPO Admin Site URL and PS Credential name. Let us create PS credential parameter.
Navigate to credentials link under left navigation menu and then click on Add a credential option present under command bar at top, Fill in the details and click on Create button to create a credential object.

Execute Script

Navigate to the Runbook and click on Start button available under command bar at top, submit the parameters and click on OK to start a job.
Once job is completed you should see the output under output window.

Comments

Popular Posts