Begin a PowerShell Runbook by Webhook in Azure Automation Utilizing Energy Automate
Introduction
Azure Automation supplies a cloud-based automation and configuration service that gives constant administration throughout your Azure and non-Azure environments. Azure Automation helps to automate frequent, time-consuming, and error-prone cloud administration duties. It consists of course of automation, replace administration, and configuration options.
Consult with my earlier article to discover ways to carry out the next actions:
- Create an Automation Account
- Create Credential Asset – To retailer the credentials which will probably be utilized by PowerShell for authentication.
- Import PowerShell Module – Import Microsoft Groups PowerShell Cmdlets module with the intention to entry Groups Cmdlets.
- Create PowerShell runbook – Script to create a brand new staff
- Check and publish the runbook
On this article, you will note tips on how to provision a staff utilizing PowerShell runbook which will probably be known as by webhook from Energy Automate when customers submit the request within the SharePoint checklist.
Design Circulation
You will notice tips on how to carry out the next actions:
- Create a SharePoint checklist – Customized checklist with default Title subject and it comprises the Staff title that must be created.
- Create PowerShell runbook
- Create a webhook
- Create a stream in Energy Automate– It will get triggered when an merchandise is created in SharePoint checklist and name the HTTP motion.
- Check the stream
Create a SharePoint checklist
- Navigate to SharePoint On-line web site.
- Create a customized checklist named as Microsoft Groups Requests.
Create PowerShell runbook
Azure Automation helps a number of kinds of runbooks. Se are going to see how we will create the PowerShell runbook with the intention to provision a staff in Microsoft Groups.
- Navigate to Automation account.
- Below Course of Automation, click on Runbooks.
- Click on Create a runbook.
- Enter the required particulars and click on
- Within the Edit pane, copy and paste the beneath script.
- Param
- (
- [Parameter (Mandatory = $false)]
- [object] $WebhookData
- )
- # If runbook was known as from Webhook, WebhookData will not be null.
- if ($WebhookData) {
- # Gather properties of WebhookData
- $WebhookName = $WebHookData.WebhookName
- $WebhookHeaders = $WebHookData.RequestHeader
- $WebhookBody = $WebHookData.RequestBody
- $Enter = (ConvertFrom-Json -InputObject $WebhookBody)
- }
- else
- {
- Write-Error -Message ‘Runbook was not began from Webhook’ -ErrorAction cease
- }
- # Get the staff title from JSON enter
- $teamName=$Enter.TeamName
- # Get the credential from Automation
- $credential = Get-AutomationPSCredential -Title “TeamsAdminCredential”
- $userName = $credential.UserName
- $securePassword = $credential.Password
- $psCredential = New-Object –TypeName System.Administration.Automation.PSCredential –ArgumentList $userName, $securePassword
- # Join to Microsoft Groups
- Join-MicrosoftTeams -Credential $psCredential
- # Create a new Staff
- New-Staff -DisplayName $teamName
- # Disconnect from Microsoft Groups
- Disconnect-MicrosoftTeams
- Click on Save.
- Publish the runbook.
- Runbook efficiently printed, as proven beneath.
Create a webhook
- Navigate to Automation account.
- Below Course of Automation, click on Runbooks.
- Click on the newly created runbook (named as CreateTeam).
- Click on Add webhook.
- Click on Create new webhook. Enter the title and duplicate the URL (You would possibly be capable of see this as soon as the webhook has been created). Click on Okay.
- Click on Parameters and run settings and click on Okay. Click on Create. Webhook created efficiently.
Create a stream in Energy Automate
- Navigate to the Energy Automate portal.
- Create a brand new stream and choose the set off as When an merchandise is created. Enter the title for the stream and click on Create.
- Choose the positioning handle and checklist title for the set off, as proven beneath.
- Add HTTP motion.
- Enter the webhook URI which was copied whereas creating the webhook. Add the JSON to the Physique, as proven beneath.
- Save the stream.
Check the stream
- Navigate to SharePoint On-line checklist. Create a brand new merchandise within the checklist.
- Below Run historical past, you may see the final run and click on on it. Circulation ran efficiently, as proven beneath.
- HTTP Request:
- From the physique, copy the Job Id which will probably be helpful in case if you have to discover the standing of the job.
- Navigate to Automation Account in Azure Portal.
- Below Course of Automation, click on Runbooks.
- Click on the newly created runbook (named as CreateTeam).
- Below Sources, click on Jobs and you’ll see the job standing. You may as well search the job based mostly on the Job Id which might be copied from the stream HTTP motion (Outputs -> Physique).
- Click on on the job to see all of the required particulars.
- The staff was created efficiently, as proven beneath.
Abstract
On this weblog, you noticed tips on how to begin a PowerShell runbook by a webhook in Azure Automation utilizing Energy Automate.