-
Notifications
You must be signed in to change notification settings - Fork 2
/
Automanage-OnboardingOneVM-UsingARMTemplate.ps1
69 lines (53 loc) · 2.45 KB
/
Automanage-OnboardingOneVM-UsingARMTemplate.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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
<#
.SYNOPSIS
Onboard a azure virtual machine to azure automanage
.DESCRIPTION
This script will execute the below operations to onboard a azure virtual machine to azure automanage
1. Get the subscription and derives the automanage account name.
2. Initialize the TemplateParameterObject for template Automanage-OnboardingOneVM.template.json.
3. Invokes New-AzDeployment for template Automanage-OnboardingOneVM.template.json.
Template Automanage-OnboardingOneVM.template.json details:
1. Creates automanage account.
2. Grants RBAC role Contributor and Resource Policy Contributor.
3. Creates Assignment for the VM.
.EXAMPLE
.\Automanage-OnboardingOneVM-UsingARMTemplate.ps1 -SubscriptionId <SubscriptionId> -VMResourceGroup <VMResourceGroup> -VMName <VMName> -VMLocation <VMLocation> -CreateAutoManageAccount <CreateAutoManageAccount>
.NOTES
AUTHOR: Azure automanage Team
LASTEDIT: Feb 04, 2021
#>
Param (
[Parameter(Mandatory = $true)]
[String] $SubscriptionId,
[Parameter(Mandatory = $true)]
[String] $VMResourceGroup,
[Parameter(Mandatory = $true)]
[String] $VMName,
[Parameter(Mandatory = $true)]
[String] $VMLocation,
[Parameter(Mandatory = $true)]
[bool] $CreateAutoManageAccount
)
# Install Az module if the Az module is not found
#Install-Module -Name Az -Force -AllowClobber
#Get-Module -Name Az.* -ListAvailable
# Connect
#Connect-AzAccount
$Subscription = Select-AzSubscription -SubscriptionId $SubscriptionId
# Parameter
$AutoManageAccountSubscriptionId = $SubscriptionId
$AutoManageAccountName = $Subscription.Subscription.Name + "-ABP"
$AutoManageAccountResourceGroup = $AutoManageAccountName + "_group"
$AutoManageAccountLocation = $VMLocation
$ARMTemplateparams = @{
autoManageAccountSubscriptionId = $AutoManageAccountSubscriptionId
autoManageAccountResourceGroup = $AutoManageAccountResourceGroup
autoManageAccountName = $AutoManageAccountName
autoManageAccountLocation = $AutoManageAccountLocation
vmResourceGroup = $VMResourceGroup
vmName = $VMName
createAutoManageAccount = $CreateAutoManageAccount
}
New-AzDeployment -Location $AutoManageAccountLocation -Name $AutoManageAccountName `
-TemplateUri https://raw.githubusercontent.com/ikanni/AutoManage-ARMTemplates/main/Automanage-OnboardingOneVM.template.json `
-TemplateParameterObject $ARMTemplateparams