@@ -26,39 +26,21 @@ This document details how to use the PowerShell in Cloud Shell in the [Azure por
26
26
27
27
## Start Cloud Shell
28
28
29
- 1 . Click on ** Cloud Shell** button from the top navigation bar of the Azure portal < br >
29
+ 1 . Click on ** Cloud Shell** button from the top navigation bar of the Azure portal
30
30
31
31
![ ] ( media/quickstart-powershell/shell-icon.png )
32
32
33
- 2 . Select the PowerShell environment from the drop-down < br >
33
+ 2 . Select the PowerShell environment from the drop-down and you will be in Azure drive ` (Azure:) `
34
34
35
35
![ ] ( media/quickstart-powershell/environment-ps.png )
36
36
37
- 3 . Select PowerShell
38
-
39
- 4 . The ` Azure drive ` appears as follows
40
-
41
- ``` Powershell
42
- Requesting a Cloud Shell... Succeeded.
43
- Connecting terminal...
44
-
45
- Welcome to Azure Cloud Shell (Preview)
46
-
47
- Type "dir" to see your Azure resources.
48
- Type "help" to learn about Cloud Shell.
49
-
50
- VERBOSE: Authenticating to Azure ...
51
- VERBOSE: Building your Azure drive ...
52
- PS Azure:\>
53
- ```
54
-
55
37
## Run PowerShell commands
56
38
57
39
Run regular PowerShell commands in the Cloud Shell, such as:
58
40
59
41
``` Powershell
60
42
PS Azure:\> Get-Date
61
- Wednesday, May 24 , 2017 11:05 :09 AM
43
+ Monday, September 25 , 2017 08:55 :09 AM
62
44
63
45
PS Azure:\> Get-AzureRmVM -Status
64
46
@@ -84,12 +66,11 @@ MyResourceGroup MyVM2 eastus Standard_DS2_v2_Promo Windows S
84
66
PS Azure:\MySubscriptionName>
85
67
```
86
68
87
- 3. View your all Azure resources under the current subscription
69
+ 3. View all your Azure resources under the current subscription
88
70
89
- Type `dir` under your subscription to get multiple views of your Azure resources.
71
+ Type `dir` to list multiple views of your Azure resources.
90
72
91
73
``` PowerShell
92
-
93
74
PS Azure:\MySubscriptionName> dir
94
75
95
76
Directory: azure:\MySubscriptionName
@@ -104,16 +85,39 @@ MyResourceGroup MyVM2 eastus Standard_DS2_v2_Promo Windows S
104
85
```
105
86
106
87
### AllResources view
107
- Type `dir` under AllResources directory to view your Azure resources.
88
+ Type `dir` under ` AllResources` directory to view your Azure resources.
108
89
109
90
PS Azure:\MySubscriptionName> dir AllResources
110
-
91
+
92
+ ### Explore resource groups
93
+
94
+ You can go to the `ResourceGroups` directory and inside a specific resource group you can find virtual machines.
95
+
96
+ ``` PowerShell
97
+ PS Azure:\MySubscriptionName> cd ResourceGroups\MyResourceGroup1\Microsoft.Compute\virtualMachines
98
+
99
+ PS Azure:\MySubscriptionName\ResourceGroups\MyResourceGroup1\Microsoft.Compute\virtualMachines> dir
100
+
101
+
102
+ Directory: Azure:\MySubscriptionName\ResourceGroups\MyResourceGroup1\Microsoft.Compute\virtualMachines
103
+
104
+
105
+ VMName Location ProvisioningState VMSize OS SKU OSVersion AdminUserName NetworkInterfaceName
106
+ ------ -------- ----------------- ------ -- --- --------- ------------- --------------------
107
+ TestVm1 westus Succeeded Standard_DS2_v2 WindowsServer 2016-Datacenter Latest AdminUser demo371
108
+ TestVm2 westus Succeeded Standard_DS1_v2 WindowsServer 2016-Datacenter Latest AdminUser demo271
109
+
110
+ ```
111
+ > [ !NOTE]
112
+ > You may notice that the second time when you type ` dir ` , the cloud shell is able to display the items much faster.
113
+ > This is because the child items are cached in memory for a better user experience.
114
+ However, you can always use ` dir -Force ` to get fresh data.
115
+
111
116
### Navigate storage resources
112
117
113
118
By entering into the ` StorageAccounts ` folder you can easily navigate your storage resources
114
119
115
120
``` PowerShell
116
-
117
121
PS Azure:\MySubscriptionName\StorageAccounts\MyStorageAccountName\Files> dir
118
122
119
123
Directory: Azure:\MySubscriptionNameStorageAccounts\MyStorageAccountName\Files
@@ -131,7 +135,6 @@ MyFileShare3 \\MyStorageAccountName.file.core.windows.net\MyFileShare3;AccountN
131
135
With the connection string, you can use the following command to mount the Azure File share.
132
136
133
137
``` PowerShell
134
-
135
138
net use <DesiredDriveLetter>: \\<MyStorageAccountName>.file.core.windows.net\<MyFileShareName> <AccountKey> /user:Azure\<MyStorageAccountName>
136
139
137
140
@@ -143,7 +146,6 @@ You can also navigate the directories under the Azure File share as follows:
143
146
144
147
145
148
``` PowerShell
146
-
147
149
PS Azure:\MySubscriptionName\StorageAccounts\MyStorageAccountName\Files> cd .\MyFileShare1\
148
150
PS Azure:\MySubscriptionName\StorageAccounts\MyStorageAccountName\Files\MyFileShare1> dir
149
151
@@ -155,12 +157,11 @@ Mode Name
155
157
156
158
```
157
159
158
- ### Interact with VMs
160
+ ### Interact with virtual machines
159
161
160
162
You can find all your virtual machines under the current subscription via ` VirtualMachines ` directory.
161
163
162
164
``` PowerShell
163
-
164
165
PS Azure:\MySubscriptionName\VirtualMachines> dir
165
166
166
167
Directory: Azure:\MySubscriptionName\VirtualMachines
@@ -175,33 +176,11 @@ TestVm10 MyResourceGroup2 eastus Standard_DS1_v2 Windows mytest
175
176
176
177
```
177
178
178
- Or you can go to the ` ResourceGroups ` directory to find the virtual machines under the current resource group.
179
-
180
-
181
- ``` PowerShell
182
-
183
- PS Azure:\MySubscriptionName\ResourceGroups\MyResourceGroup1\Microsoft.Compute\virtualMachines> dir
184
-
185
-
186
- Directory: Azure:\MySubscriptionName\ResourceGroups\MyResourceGroup1\Microsoft.Compute\virtualMachines
187
-
188
-
189
- VMName Location ProvisioningState VMSize OS SKU OSVersion AdminUserName NetworkInterfaceName
190
- ------ -------- ----------------- ------ -- --- --------- ------------- --------------------
191
- TestVm1 westus Succeeded Standard_DS2_v2 WindowsServer 2016-Datacenter Latest AdminUser demo371
192
- TestVm2 westus Succeeded Standard_DS1_v2 WindowsServer 2016-Datacenter Latest AdminUser demo271
193
-
194
- ```
195
- > [ !NOTE]
196
- > You may notice that the second time when you type ` dir ` , the cloud shell is able to display the items much faster.
197
-
198
- This is because the child items are cached in memory for a better user experience.
199
- However, you can always use ` dir -force ` to get fresh data.
200
-
201
-
202
-
203
179
#### Invoke PowerShell script across remote VMs
204
180
181
+ > [ !WARNING]
182
+ > Please refer to [ Troubleshooting remote management of Azure VMs] ( troubleshooting.md#powershell-resolutions ) .
183
+
205
184
Assuming you have a VM, MyVM1, let's use ` Invoke-AzureRmVMCommand ` to invoke a PowerShell scriptblock on the remote machine.
206
185
207
186
``` Powershell
@@ -243,10 +222,11 @@ You can also navigate to the `virtualMachines` directory first and run `Enter-Az
243
222
PS Azure:\MySubscriptionName\ResourceGroups\MyResourceGroup\Microsoft.Compute\virtualMachines> Get-Item MyVM1 | Enter-AzureRmVM
244
223
```
245
224
246
- ### WebApps
225
+ ### Discover WebApps
247
226
248
- ``` PowerShell
227
+ By entering into the ` WebApps ` folder you can easily navigate your storage resources
249
228
229
+ ``` PowerShell
250
230
PS Azure:\MySubscriptionName> dir .\WebApps\
251
231
252
232
Directory: Azure:\MySubscriptionName\WebApps
@@ -287,9 +267,9 @@ Under `Azure` drive, type `Get-AzureRmCommand` to get context specific Azure com
287
267
288
268
Alternatively, you can always use ` Get-Command *azurerm* -Module AzureRM.* ` to find out the available Azure commands.
289
269
290
- ## Install modules
270
+ ## Install custom modules
291
271
292
- You can run ` Install-Module ` to install modules from the [ PowerShellGallery.com ] [ gallery ] .
272
+ You can run ` Install-Module ` to install modules from the [ PowerShell Gallery ] [ gallery ] .
293
273
294
274
## Get-Help
295
275
@@ -317,32 +297,38 @@ PS C:\users\ContainerAdministrator\CloudDrive> .\helloworld.ps1
317
297
Hello World!
318
298
```
319
299
320
- Next time when you use PowerShell in Cloud Shell, the ` helloworld.ps1 ` file should still exist under the ` CloudDrive ` folder mounts your Azure cloud files share.
300
+ Next time when you use PowerShell in Cloud Shell, the ` helloworld.ps1 ` file will exist under the ` CloudDrive ` folder that mounts your Azure File share.
321
301
322
- ## User custom profile
302
+ ## Use custom profile
323
303
324
- If you want to customize your environment, you can create a PowerShell profile, name it as ` Microsoft.PowerShell_profile. ps1` or ` profile. ps1` and save it under the CloudDrive so that it can be loaded to every PowerShell session when you launch the Cloud Shell.
304
+ You can customize your PowerShell environment, by creating PowerShell profile(s) - ` profile. ps1` or ` Microsoft.PowerShell_profile. ps1` . Save it under the ` CloudDrive ` so that it can be loaded in every PowerShell session when you launch the Cloud Shell.
325
305
326
306
For how to create a profile, refer to [ About Profiles] [ profile ] .
327
307
328
308
## Use Git
329
309
330
- To clone a repo in the CloudShell, you need to create a [ personal access token] [ githubtoken ] and use it as username. Once you have your token clone the repository as follows:
310
+ To clone a git repo in the CloudShell, you need to create a [ personal access token] [ githubtoken ] and use it as the username. Once you have your token, clone the repository as follows:
331
311
332
312
``` PowerShell
333
313
git clone https://<your-access-token>@github.com/username/repo.git
334
314
335
315
```
336
-
337
- As the CloudShell session will be gone once you sign out or the session gets timed out, the git config file will not be persisted. To avoid entering your git identity every time you use git, you may add git config information in your custom profile. For example you may add the following to your profile.ps1.
316
+ Since sessions in CloudShell do not persist when you sign out or the session times out, the Git config file will not exist upon the next logon. To have your Git config persist, you must save your .gitconfig to your ` CloudDrive ` and copy it or create a symlink when the ` CloudShell ` gets launched. Use the following code snippet in your profile.ps1, to create a symlink to ` CloudDrive ` .
338
317
339
318
``` PowerShell
340
319
341
- git config --global user.name "John Doe"
342
- git config --global user.email johndoe@example.com
320
+ # .gitconfig path relative to this script
321
+ $script:gitconfigPath = Join-Path $PSScriptRoot .gitconfig
343
322
344
- ```
323
+ # Create a symlink to .gitconfig in user's $home
324
+ if(Test-Path $script:gitconfigPath){
325
+
326
+ if(-not (Test-Path (Join-Path $Home .gitconfig ))){
327
+ New-Item -ItemType SymbolicLink -Path $home -Name .gitconfig -Value $script:gitconfigPath
328
+ }
329
+ }
345
330
331
+ ```
346
332
## Exit the shell
347
333
348
334
Type ` exit ` to close the session.
0 commit comments