
Azure Functions For SharePoint Operations Using CSOM PowerShell
Introduction
In this article, you will learn how to create Azure function apps for the SharePoint operations using client side object model PowerShell scripts.
Note: Azure functions is the way to run the solutions or piece of code over the cloud. It helps in processing the data, or integrating other systems or even works with the internet of things.
In this sample, let us see how to integrate SharePoint operations on to Azure functions app using CSOM PowerShell. Any complex CSOM powershell code can be written and executed on the cloud.
Functions can be triggered in multiple ways. Here we will create HTTP trigger function. More details and pricing information about the Azure functions can be found here.
Prerequisites
Microsoft Azure account with Azure functions app.
SharePoint online portal
Create Function App
From the azure portal, create new function app.
Under function app, create new function using HttpTrigger-PowerShell template (If the template is not listed, select all options from language and scenario dropdowns).
Importing SharePoint Assemblies
By default only the system assemblies are present on the Azure functions. To load the external assemblies, we need to import the assemblies into the function and then refer to it in the code.
SharePoint CSOM PowerShell assemblies need to be uploaded. Upload the required assembly files using Kudu tool. From the app settings page, select advanced tools under development tools and click on go. The tools page will be opened. Under debug console, select PowerShell. Navigate to the appropriate function (site -> wwwroot -> FunctionName). Create the bin folder and upload the necessary files.
Note
If the deployment credentials are not set, then set the credentials from the app settings page and then proceed uploading the assemblies.
Upload the required reference files (.dll). For SharePoint operations, Microsoft.SharePoint.Client.dll and Microsoft.SharePoint.Client.Runtime.dll files are required. These are the client side reference files required for PowerShell CSOM operations. The files can be downloaded from the Microsoft site