Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 06599e3

Browse files
committedSep 20, 2017
Updates to quickstart-ps
1 parent 52bdaad commit 06599e3

File tree

2 files changed

+55
-69
lines changed

2 files changed

+55
-69
lines changed
 
Loading

‎articles/cloud-shell/quickstart-powershell.md

Lines changed: 55 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -26,39 +26,21 @@ This document details how to use the PowerShell in Cloud Shell in the [Azure por
2626
2727
## Start Cloud Shell
2828

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
3030

3131
![](media/quickstart-powershell/shell-icon.png)
3232

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:)`
3434

3535
![](media/quickstart-powershell/environment-ps.png)
3636

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-
5537
## Run PowerShell commands
5638

5739
Run regular PowerShell commands in the Cloud Shell, such as:
5840

5941
```Powershell
6042
PS Azure:\> Get-Date
61-
Wednesday, May 24, 2017 11:05:09 AM
43+
Monday, September 25, 2017 08:55:09 AM
6244
6345
PS Azure:\> Get-AzureRmVM -Status
6446
@@ -84,12 +66,11 @@ MyResourceGroup MyVM2 eastus Standard_DS2_v2_Promo Windows S
8466
PS Azure:\MySubscriptionName>
8567
```
8668
87-
3. View your all Azure resources under the current subscription
69+
3. View all your Azure resources under the current subscription
8870
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.
9072
9173
``` PowerShell
92-
9374
PS Azure:\MySubscriptionName> dir
9475
9576
Directory: azure:\MySubscriptionName
@@ -104,16 +85,39 @@ MyResourceGroup MyVM2 eastus Standard_DS2_v2_Promo Windows S
10485
```
10586
10687
### AllResources view
107-
Type `dir` under AllResources directory to view your Azure resources.
88+
Type `dir` under `AllResources` directory to view your Azure resources.
10889
10990
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+
111116
### Navigate storage resources
112117

113118
By entering into the `StorageAccounts` folder you can easily navigate your storage resources
114119

115120
``` PowerShell
116-
117121
PS Azure:\MySubscriptionName\StorageAccounts\MyStorageAccountName\Files> dir
118122
119123
Directory: Azure:\MySubscriptionNameStorageAccounts\MyStorageAccountName\Files
@@ -131,7 +135,6 @@ MyFileShare3 \\MyStorageAccountName.file.core.windows.net\MyFileShare3;AccountN
131135
With the connection string, you can use the following command to mount the Azure File share.
132136

133137
``` PowerShell
134-
135138
net use <DesiredDriveLetter>: \\<MyStorageAccountName>.file.core.windows.net\<MyFileShareName> <AccountKey> /user:Azure\<MyStorageAccountName>
136139
137140
@@ -143,7 +146,6 @@ You can also navigate the directories under the Azure File share as follows:
143146

144147
145148
``` PowerShell
146-
147149
PS Azure:\MySubscriptionName\StorageAccounts\MyStorageAccountName\Files> cd .\MyFileShare1\
148150
PS Azure:\MySubscriptionName\StorageAccounts\MyStorageAccountName\Files\MyFileShare1> dir
149151
@@ -155,12 +157,11 @@ Mode Name
155157
156158
```
157159

158-
### Interact with VMs
160+
### Interact with virtual machines
159161

160162
You can find all your virtual machines under the current subscription via `VirtualMachines` directory.
161163

162164
``` PowerShell
163-
164165
PS Azure:\MySubscriptionName\VirtualMachines> dir
165166
166167
Directory: Azure:\MySubscriptionName\VirtualMachines
@@ -175,33 +176,11 @@ TestVm10 MyResourceGroup2 eastus Standard_DS1_v2 Windows mytest
175176
176177
```
177178

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-
203179
#### Invoke PowerShell script across remote VMs
204180

181+
> [!WARNING]
182+
> Please refer to [Troubleshooting remote management of Azure VMs](troubleshooting.md#powershell-resolutions).
183+
205184
Assuming you have a VM, MyVM1, let's use `Invoke-AzureRmVMCommand` to invoke a PowerShell scriptblock on the remote machine.
206185

207186
``` Powershell
@@ -243,10 +222,11 @@ You can also navigate to the `virtualMachines` directory first and run `Enter-Az
243222
PS Azure:\MySubscriptionName\ResourceGroups\MyResourceGroup\Microsoft.Compute\virtualMachines> Get-Item MyVM1 | Enter-AzureRmVM
244223
```
245224

246-
### WebApps
225+
### Discover WebApps
247226

248-
``` PowerShell
227+
By entering into the `WebApps` folder you can easily navigate your storage resources
249228

229+
``` PowerShell
250230
PS Azure:\MySubscriptionName> dir .\WebApps\
251231
252232
Directory: Azure:\MySubscriptionName\WebApps
@@ -287,9 +267,9 @@ Under `Azure` drive, type `Get-AzureRmCommand` to get context specific Azure com
287267

288268
Alternatively, you can always use `Get-Command *azurerm* -Module AzureRM.*` to find out the available Azure commands.
289269

290-
## Install modules
270+
## Install custom modules
291271

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].
293273

294274
## Get-Help
295275

@@ -317,32 +297,38 @@ PS C:\users\ContainerAdministrator\CloudDrive> .\helloworld.ps1
317297
Hello World!
318298
```
319299

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.
321301

322-
## User custom profile
302+
## Use custom profile
323303

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.
325305

326306
For how to create a profile, refer to [About Profiles][profile].
327307

328308
## Use Git
329309

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:
331311

332312
``` PowerShell
333313
git clone https://<your-access-token>@github.com/username/repo.git
334314
335315
```
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`.
338317

339318
``` PowerShell
340319
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
343322
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+
}
345330
331+
```
346332
## Exit the shell
347333

348334
Type `exit` to close the session.

0 commit comments

Comments
 (0)
Please sign in to comment.