Adding Users to Distribution Lists using Azure Runbooks

Using Torii Custom Actions to trigger Azure Runbooks

There are some preliminary steps to get started with Azure Runbooks, however if you are familiar with them the process to integrate with Torii is very straightforward.

If you have not previously worked with Azure Runbooks and need some help getting started this blog post will help you get started.

1. In your Azure Automation account, create a new runbook

  • Give your runbook a Name.
  • Set the Runbook type to Powershell.
  • Set the Runtime version for the runbook

2. Add Powershell code to add users to distribution lists

The code sample to add users to distribution lists can be found in the referenced blog post or below, note that you should replace <YOUR_DOMAIN> with the value for your O365 domain:

param(
      [object]$WebhookData
)
try {
    "Logging in to Exchange O365"
    Connect-ExchangeOnline -ManagedIdentity -Organization <YOUR_DOMAIN>.onmicrosoft.com
    "Adding user..."
    $webhookBodyObject = (ConvertFrom-Json -InputObject $WebhookData.RequestBody)
    Write-Output "Hello $webhookBodyObject"
    Write-Output $webhookBodyObject.email
    Write-Output $webhookBodyObject.distribution_list_id
    Add-DistributionGroupMember -Identity $webhookBodyObject.distribution_list_id -Member $webhookBodyObject.email
    "User Added"
} catch {
    Write-Error -Message $_.Exception
    throw $_.Exception
}

3. After the runbook has been created, add a webhook

The webhook URL will be used in the Torii custom action to execute the runbook from a workflow. Copy the URL once you have added the webhook.

4. In Torii create a workflow with a custom action, or add a custom action to an existing workflow from which you will call this runbook.

The body of the custom action request that calls the Azure runbook will be as follows:

{
  "email":  "[Trigger.User.Email]",
  "distribution_list_id":  "YOUR_DISTRIBUTION_LIST_ID"
}

5. Execute your Torii workflow and test the execution of your runbook

Test your Torii workflow by pressing the play button at the top of the workflow canvas.

You should also verify execution of the runbook in Azure as in the screenshot below.

👍

Congratulations, you've configured a Torii workflow to execute an Azure runbook with a custom action!