-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathStart-VMsFromWebhook.ps1
More file actions
34 lines (29 loc) · 1.1 KB
/
Copy pathStart-VMsFromWebhook.ps1
File metadata and controls
34 lines (29 loc) · 1.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
workflow Start-VMsFromWebhook
{
param (
[object]$WebhookData
)
# If runbook was called from Webhook, WebhookData will not be null.
if ($WebhookData -ne $null) {
# Collect properties of WebhookData
$WebhookName = $WebhookData.WebhookName
$WebhookHeaders = $WebhookData.RequestHeader
$WebhookBody = $WebhookData.RequestBody
# Collect individual headers. VMList converted from JSON.
$From = $WebhookHeaders.From
$VMList = ConvertFrom-Json -InputObject $WebhookBody
Write-Output "Runbook started from webhook $WebhookName by $From."
# Authenticate to Azure resources
$Cred = Get-AutomationPSCredential -Name 'ContosoAccount'
Add-AzureAccount -Credential $Cred
# Start each virtual machine
foreach ($VM in $VMList)
{
Write-Output "Starting $VM.Name."
Start-AzureVM -Name $VM.Name -ServiceName $VM.ServiceName
}
}
else {
Write-Error "Runbook meant to be started only from a webhook."
}
}