What if you could run PowerShell scripts directly from Power Automate? After attending the Global Automation Bootcamp and seeing demos by Ben Stegink and Jaap Brasser, I was inspired to build a PowerShell Azure Runbook called from Power Automate using the Azure Automation Create Job step. Here’s how I did it.

The Problem — SharePoint External Sharing

My employer has a policy where all new SharePoint sites are setup with external sharing disabled and the only way to change this setting (as of today) is via the Admin GUI or PowerShell. We have a requirement to change the default setting to existing guests if manager approval has been granted, PowerAutomate has Approvals built in. This is the perfect opportunity for PowerShell to meet PowerAutomate.

SharePoint External Sharing Disabled

Creating the Azure Automation Runbook

I have previously used SharePoint Powershell CMD Lets to manage SharePoint Online and so thought I would fully automated this process.

First off, I have created an Azure Automation Account that then allowed me to create a RunBook specifically for the task ahead. The CMD Let I am looking to run is Set-SPOSite. I accept a variable input for the Site URL and in return I have some error handling and confirmation of the changes made to the SharingCapability setting.

My runbook with PowerShell Script

Calling the Runbook from Power Automate

Calling the PowerShell Automation is straight forward. Make a connection to Azure Automation Connector and then select Create Job. I have chosen for the step to wait for the job to complete and then get the job output which includes a JSON of the outcome and the various settings retrieved from GET-SPOSITE.

Built on my personal Dev tenant with an Azure Trial

What’s Next

This opens up so many opportunities. My next job is to manage dormant guests that are on our tenant. I wrote a PowerShell script months ago that can be run manually, but now I have the excuse to fully automate it thanks to another great weekend of demonstrations.

If you have any ideas for this technology, please get in touch. I will happily build you a proof of concept in order to supplement my blog and my learning.