We’ve got the form and approvals working. Now we build the piece that actually creates the SharePoint site. This lives in Azure Automation — think of it as a cloud robot that runs a script whenever we tell it to.
First, Set Up Azure Automation
- Go to the Azure portal (portal.azure.com)
- Search for “Automation Accounts”
- Create a new one (or use an existing one from your Cloud team)
- Once created, go to “Runtime Environments”
- Create one using “PowerShell 7.2”
- Add the “PnP.PowerShell” module to it (this is the tool that talks to SharePoint)
Import Your Certificate
Remember that certificate file from Part 1?
- In your Automation Account, go to “Certificates”
- Click “Add a certificate”
- Name it “SharePoint-Provisioner-Cert”
- Upload the file ending in .pfx
- Enter the password you set earlier
Create the Runbook
A “runbook” is just a script that Azure runs for you.
- Go to “Runbooks”
- Click “Create a runbook”
- Name it “SiteProvision-Real”
- Choose type “PowerShell” and runtime “7.2”
- Click “Create”
Now paste in the script. It runs in six stages:
Stage 1 receives the request details from your approval flow.
Stage 2 logs in to SharePoint using the certificate (no passwords needed).
Stage 3 creates the actual site:
New-PnPSite -Type CommunicationSite -Title $siteTitle -Url $targetSiteUrl -Owner $primaryOwner -Wait
Stage 4 sets up permissions. This is the clever part. Instead of giving the requester full control (where they could accidentally delete the site), we:
- Make the admin team the true owners
- Give the requester “Design” access (they can manage content but not destroy the site)
- Assign the member and visitor groups appropriately
Stage 5 updates the request list to say “Provisioned” and adds the site link.
Stage 6 triggers the notification email from Part 2.
Connect It to Your Approval Flow
- In your runbook, click “Add webhook”
- Name it, set it to expire in one year
- Copy the web address it gives you (you only see this once, so save it!)
- Go back to your MainApprovalFlow from Part 2
- Paste this address into the HTTP action’s URL field
One Important Tip
When adding a security group to SharePoint in the script, use this special format:
c:0t.c|tenant|THE-GROUP-ID
Not the group’s name. This trips up a lot of people.
What’s Next
In the final part, we’ll build the user-friendly form that starts it all — plus I’ll share the lessons I learned the hard way so you can avoid them.