-
Notifications
You must be signed in to change notification settings - Fork 2
/
Azure Resource Manager (ARM) Resource Providers.ps1
174 lines (125 loc) · 5.56 KB
/
Azure Resource Manager (ARM) Resource Providers.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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
<#########################################################
Author: Trevor Sullivan <trevor@artofshell.com>
Description: This PowerShell script demonstrates how to deploy a Microsoft
Azure Resource Manager (ARM) JSON template using Windows PowerShell.
COPYRIGHT NOTICE
This file is part of the "Microsoft Azure Resource Manager (ARM)" training course, and is
copyrighted by Art of Shell LLC. This file may not be copied or distributed, without
written permission from an authorized member of Art of Shell LLC (https://artofshell.com).
For more information, please contact info@artofshell.com.
#########################################################>
### Install the AzureRM PowerShell module
Install-Module -Name AzureRM -Scope CurrentUser;
### Inspect Azure Resource Manager (ARM) PowerShell modules
Clear-Host;
Get-Module -ListAvailable -Name AzureRM*;
### Inspect commands in the ARM PowerShell modules
Get-Command -Module AzureRM*;
### Inspect commands in the AzureRM.Profile module
Get-Command -Module AzureRM.Profile;
### Authenticate to Microsoft Azure
$AzureUsername = 'aos@artofshell.com';
$AzureCredential = Get-Credential -Message 'Please enter your Microsoft Azure password.' -UserName $AzureUsername;
Add-AzureRmAccount -Credential $AzureCredential;
#region Subscription Management
### List available Microsoft Azure subscriptions, after authenticating
Get-AzureRmSubscription;
### Select a subscription to operate on
### Command alias: Select-AzureRmSubscription
Set-AzureRmContext -SubscriptionId 1c9fd9f5-a2dc-4cc9-a73c-cab0ee4a95a1;
Set-AzureRmContext -SubscriptionName 'Visual Studio Ultimate with MSDN';
#endregion
#region Azure Resource Manager (ARM) Resource Providers
Clear-Host;
Get-Command -Name *provider* -Module AzureRM.Resources;
### Get a list of all registered Azure Resource Manager (ARM) Resource Providers
Get-AzureRmResourceProvider;
### Get a list of all Azure Resource Manager (ARM) Resource Providers
Get-AzureRmResourceProvider -ListAvailable;
### Register an Azure Resource Manager (ARM) Resource Provider
Register-AzureRmResourceProvider -ProviderNamespace Microsoft.StreamAnalytics -Force;
### Unregister an Azure Resource Manager (ARM) Resource Provider
Unregister-AzureRmResourceProvider -ProviderNamespace Microsoft.StreamAnalytics -Force;
### Get Resource Provider-specific features
Get-AzureRmProviderFeature;
### Register a Resource Provider-specific feature
Register-AzureRmProviderFeature -ProviderNamespace Microsoft.Automation -FeatureName dsc -Force;
#endregion
#region Azure Resource Manager (ARM) Resource Groups
Get-Command -Module AzureRM* -Name *ResourceGroup*;
$ResourceGroup = @{
Name = 'artofshell-storage';
Location = 'North Central US';
Tag = @(
@{ Name = 'Department';
Value = 'Marketing'; }
);
Force = $true;
};
New-AzureRmResourceGroup @ResourceGroup;
### Update the Department tag on the Resource Group
Set-AzureRmResourceGroup -Name $ResourceGroup.Name `
-Tag @{ Name = 'Department'; Value = 'DevOps'; };
### Search for a Resource Group that matches a tag
Find-AzureRmResourceGroup -Tag @{ Name = 'Department'; Value = 'DevOps'; }
#endregion
#region Manage Azure resource using generic Resource Management interface
Get-Command -Module AzureRM.Resources;
$StorageAccountResource = @{
ResourceGroupName = $ResourceGroup.Name
Name = 'contosostorage6';
Location = 'West Europe';
ResourceType = 'Microsoft.Storage/storageAccounts';
ApiVersion = '2015-06-15';
Properties = @{
accountType = 'Standard_LRS'
};
};
New-AzureRmResource @StorageAccountResource;
#endregion
#region Manage Azure resources using resource-specific interfaces
### Benefits:
###
### - More PowerShell friendly (parameter names and Intellisense / auto-completion)
### - Doesn't require you to remember API Version and exact Resource Type
### - Commands are more easily discoverable, using Get-Command
### Availability Set commands
Get-Command -Name *availabilityset*;
$AvailabilitySet = @{
ResourceGroupName = $ResourceGroup.Name;
Location = 'West Europe';
Name = 'AVSet-ArtofShell-Database';
};
New-AzureRmAvailabilitySet @AvailabilitySet;
### Virtual Machine commands
Get-Command -Module AzureRM* -Name *vm*;
### Obtain a list of Azure Virtual Machines
Get-AzureRmVm;
### Start an Azure Virtual Machine
Start-AzureRmVm -Name Trevor -ResourceGroupName MYCOOLRESOURCEGROUP;
### Stop an Azure Virtual Machines
Stop-AzureRmVm -Name Trevor -ResourceGroupName MYCOOLRESOURCEGROUP;
#endregion
#region Deploy declarative Microsoft Azure Resource Manager (ARM) JSON Templates
### Search for ARM Resource Group deployment-related commands
Get-Command -Module AzureRM.Resources -Name *deployment;
### Perform a declarative deployment of an Azure Resource Manager (ARM) JSON Template
$Deployment = @{
ResourceGroupName = $ResourceGroup.Name;
TemplateUri = 'https://raw.githubusercontent.com/Azure/azure-quickstart-templates/master/101-vm-simple-linux/azuredeploy.json';
TemplateParameterObject = @{
adminUsername = 'artofshell';
adminPassword = 'P@ssw0rd!!';
dnsLabelPrefix = 'artofshell-arm';
};
Mode = 'Complete'; ### Alternative is "incremental"
Force = $true;
Name = 'artofshell-armdeploy';
};
New-AzureRmResourceGroupDeployment @Deployment;
### Obtain the status of the Resource Group Deployment, and input/output parameters
Get-AzureRmResourceGroupDeployment -ResourceGroupName $ResourceGroup.Name -Name $Deployment.Name;
### View a log of deployments
Get-AzureRmLog -ResourceGroup $ResourceGroup.Name;
#endregion
### FIN