The Runbook will run a PowerShell script, which connects to Teams, gest the queue details, and stores them in a JSON file in the Container.
To create it, follow the steps below.
1. Go to the Automation Account you created earlier.
On the left menu, under Process Automation, click on Runbooks.
2. On the top menu click on + Create a runbook
Give a name (based on your naming convention) to the Runbook, select PowerShell as a type, and runtime verson 5.1, as shown in the example below.
Click on Review + Create and then Create.
3. Copy and paste the following code into the Runbook:
# Authenticate to Teams
$identityObjectId = Get-AutomationVariable -Name 'UserAssignedIdentityObjectId'
$ClientSecret = Get-AutomationVariable -Name 'ClientSecret'
$ApplicationID = Get-AutomationVariable -Name 'ApplicationID'
$TenantID = Get-AutomationVariable -Name 'TenantID'
$graphtokenBody = @{
Grant_Type = "client_credentials"
Scope = "https://graph.microsoft.com/.default"
Client_Id = $ApplicationID
Client_Secret = $ClientSecret
}
$graphToken = Invoke-RestMethod -Uri "https://login.microsoftonline.com/$TenantID/oauth2/v2.0/token" -Method POST -Body $graphtokenBody | Select-Object -ExpandProperty Access_Token
$teamstokenBody = @{
Grant_Type = "client_credentials"
Scope = "48ac35b8-9aa8-4d74-927d-1f4a14a0b239/.default"
Client_Id = $ApplicationID
Client_Secret = $ClientSecret
}
$teamsToken = Invoke-RestMethod -Uri "https://login.microsoftonline.com/$TenantID/oauth2/v2.0/token" -Method POST -Body $teamstokenBody | Select-Object -ExpandProperty Access_Token
Connect-MicrosoftTeams -AccessTokens @("$graphToken", "$teamsToken")
$output = Get-CsCallQueue|ConvertTo-Json|Out-File out.json
Connect-AzAccount -Identity -AccountId $identityObjectId -TenantId $TenantID
# Define Variables
$subscriptionId = Get-AutomationVariable -Name 'SubscriptionId'
$storageAccountRG = Get-AutomationVariable -Name 'StorageAccountRG'
$storageAccountName = Get-AutomationVariable -Name 'StorageAccountName'
$storageContainerName = Get-AutomationVariable -Name 'StorageContainerName'
# Select right Azure Subscription
Select-AzSubscription -SubscriptionId $subscriptionId
# Get Storage Account Key
$storageAccountKey = (Get-AzStorageAccountKey -ResourceGroupName $storageAccountRG -AccountName $storageAccountName).Value[0]
# Set AzStorageContext
$ctx = New-AzStorageContext -StorageAccountName $storageAccountName -StorageAccountKey $storageAccountKey
Set-AzStorageBlobContent -Force -Container $storageContainerName -File out.json -Blob call-queues-result.json -Context $ctx
4. Click Publish to complete the Runbook creation.
5. Now run the run book once, using the start button, to see the outcome of it.
The call queue JSON file should now be generated within the storage account container that was created in the preceding steps.
Please proceed on creating the Webhook.