-
Notifications
You must be signed in to change notification settings - Fork 96
/
azure-powershell.ps1
196 lines (141 loc) · 8.69 KB
/
azure-powershell.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
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
# -------------------------------------------------------------------------------------- #
# -------------------------- Azure Powershell Commands --------------------------------- #
# -------------------------------------------------------------------------------------- #
# This file is a collection of Azure Powershell Commands.
# It can be used to quickly look up certain commands.
# This enables you to faster deploy and manage resources on Azure.
# You might encounter issues trying to run the Azure Cmdlets if the necessary installations have not been made.
# Remember to run as administrator when installing all the modules.
# If you use a Windows version before Windows 10, you will need to install
# -------------------------------------------------------------------------------------- #
# ------------------------------ Getting Started --------------------------------------- #
# -------------------------------------------------------------------------------------- #
# Install the Azure Resource Manager modules from the PowerShell Gallery
Install-Module AzureRM
# Before you can execute commands, you need to add your Azure account
# You can add different parameters. This is the simple version.
Add-AzureAccount -Environment MyEnvironment
# Login to Azure Account
$cred = Get-Credential
Login-AzureRmAccount -Credential $cred
# Simple login - You will be prompted to login in a browser.
Login-AzureRmAccount
# To view all subscriptions for your account
Get-AzureRmSubscription
# To select a default subscription for your current session.
# This is useful when you have multiple subscriptions.
Get-AzureRmSubscription -SubscriptionName "your sub" | Select-AzureRmSubscription
# View your current Azure PowerShell session context
# This session state is only applicable to the current session and will not affect other sessions
Get-AzureRmContext
# To select the default storage context for your current session
Set-AzureRmCurrentStorageAccount -ResourceGroupName "your resource group" -StorageAccountName "your storage account name"
# View your current Azure PowerShell session context
# Note: the CurrentStorageAccount is now set in your session context
Get-AzureRmContext
# To list all of the blobs in all of your containers in all of your accounts
Get-AzureRmStorageAccount | Get-AzureStorageContainer | Get-AzureStorageBlob
# -------------------------------------------------------------------------------------- #
# ------------------------- Account and Subscription Details --------------------------- #
# -------------------------------------------------------------------------------------- #
# Display available accounts
Get-AzureAccount
# Display your Azure Subscriptions
Get-AzureRmSubscription
# -------------------------------------------------------------------------------------- #
# ----------------------------------- ARM Templates ------------------------------------ #
# -------------------------------------------------------------------------------------- #
# Create a new resource group and deploy an ARM template
New-AzureRmResourceGroup -Name ExampleResourceGroup -Location "West US"
New-AzureRmResourceGroupDeployment -Name ExampleDeployment -ResourceGroupName ExampleResourceGroup -TemplateFile c:\MyTemplates\example.json -TemplateParameterFile c:\MyTemplates\example.params.json
# -------------------------------------------------------------------------------------- #
# -------------------------------------- Account --------------------------------------- #
# -------------------------------------------------------------------------------------- #
$subscr="<subscription name>"
$staccount="<storage account name>"
Select-AzureSubscription -SubscriptionName $subscr –Current
Set-AzureSubscription -SubscriptionName $subscr -CurrentStorageAccountName $staccount
# -------------------------------------------------------------------------------------- #
# ------------------------------ Automation Variables ---------------------------------- #
# -------------------------------------------------------------------------------------- #
# Create a new variable with Powershell
New-AzureRmAutomationVariable -ResourceGroupName "ResouceGroup01"
–AutomationAccountName "MyAutomationAccount" –Name 'MyStringVariable' `
–Encrypted $false –Value 'My