Public/Register-AzureRmStartVmScheduleRunbook.ps1

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
35
36
37
38
39
40
41
42
43
44
45
Set-StrictMode -Version Latest

<#
.SYNOPSIS
Associate a schedule to the Start virtual machine runbook.
 
.EXAMPLE
Register-AzureRmStartVmScheduleRunbook -ResourceGroupName rg01 -AutomationAccountName aa01 -VmName myvm -ScheduleName NineOclock
 
#>

function Register-AzureRmStartVmScheduleRunbook {
    param(
        [parameter(mandatory=$true)]
        [String]
        $ResourceGroupName,

        [ValidateLength(6,50)]
        [parameter(mandatory=$true)]
        [String]
        $AutomationAccountName,

        [parameter(mandatory=$true)]
        [String]
        $VmName,

        [parameter(mandatory=$true)]
        [String]
        $ScheduleName
    )

    [String]$RunbookName = 'Start-SingleAzureRmVm'

    $ScheduleParams = @{
        ResourceGroupName=$ResourceGroupName;
        VmName=$VmName
    }

    Register-AzureRmAutomationScheduledRunbook `
        -ResourceGroupName $ResourceGroupName `
        -AutomationAccountName $AutomationAccountName `
        -Parameters $ScheduleParams `
        -RunbookName $RunbookName `
        -ScheduleName $ScheduleName
}