Skip to content

Commit 75181de

Browse files
author
Maddie Clayton
authored
Merge pull request Azure#8542 from maddieclayton/msiexample
Update documentation for MSI
2 parents e09ab72 + 360d147 commit 75181de

File tree

2 files changed

+54
-4
lines changed

2 files changed

+54
-4
lines changed

src/Accounts/Accounts/ChangeLog.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
- Additional information about change #1
1919
-->
2020
## Upcoming Release
21+
* Update examples for Connect-AzAccount
2122
* Add additional framework extensions for .Net Framework execution
2223

2324
## Version 1.3.0

src/Accounts/Accounts/help/Connect-AzAccount.md

Lines changed: 53 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,7 @@ The ServicePrincipal switch parameter indicates that the account authenticates a
114114
### Example 3: Use an interactive login to connect to an account for a specific tenant and subscription
115115
```powershell
116116
PS C:\> Connect-AzAccount -Tenant "xxxx-xxxx-xxxx-xxxx" -SubscriptionId "yyyy-yyyy-yyyy-yyyy"
117+
117118
Account SubscriptionName TenantId Environment
118119
------- ---------------- -------- -----------
119120
[email protected] Subscription1 xxxx-xxxx-xxxx-xxxx AzureCloud
@@ -123,7 +124,7 @@ This command connects to an Azure account and configured AzureRM PowerShell to r
123124

124125
### Example 4: Add an Account Using Managed Service Identity Login
125126
```powershell
126-
PS C:\> Connect-AzAccount -MSI
127+
PS C:\> Connect-AzAccount -Identity
127128
128129
Account SubscriptionName TenantId Environment
129130
------- ---------------- -------- -----------
@@ -133,7 +134,35 @@ MSI@50342 Subscription1 xxxx-xxxx-xxxx-xxxx AzureCloud
133134
This command connects using the managed service identity of the host environment (for example, if executed on a
134135
VirtualMachine with an assigned Managed Service Identity, this will allow the code to login using that assigned identity)
135136

136-
### Example 5: Add an account using certificates
137+
### Example 5: Add an Account Using Managed Service Identity Login and ClientId
138+
```powershell
139+
PS C:\> $identity = Get-AzUserAssignedIdentity -ResourceGroupName "myResourceGroup" -Name "myUserAssignedIdentity"
140+
PS C:\> Get-AzVM -ResourceGroupName contoso -Name testvm | Update-AzVM -IdentityType UserAssigned -IdentityId $identity.Id
141+
PS C:\> Connect-AzAccount -Identity -AccountId $identity.ClientId # Run on the "testvm" virtual machine
142+
143+
Account SubscriptionName TenantId Environment
144+
------- ---------------- -------- -----------
145+
yyyy-yyyy-yyyy-yyyy Subscription1 xxxx-xxxx-xxxx-xxxx AzureCloud
146+
```
147+
148+
This command connects using the managed service identity of "myUserAssignedIdentity" by adding the User Assigned Identity to the Virtual Machine, then connecting using the ClientId of the User Assigned Identity.
149+
More information about configuring Managed Identities can be found here: https://docs.microsoft.com/en-us/azure/active-directory/managed-identities-azure-resources/qs-configure-powershell-windows-vm.
150+
151+
### Example 6: Add an Account Using Managed Service Identity Login and ClientId
152+
```powershell
153+
PS C:\> $identity = Get-AzUserAssignedIdentity -ResourceGroupName "myResourceGroup" -Name "myUserAssignedIdentity"
154+
PS C:\> Get-AzVM -ResourceGroupName contoso -Name testvm | Update-AzVM -IdentityType UserAssigned -IdentityId $identity.Id
155+
PS C:\> Connect-AzAccount -Identity -AccountId $identity.Id # Run on the "testvm" virtual machine
156+
157+
Account SubscriptionName TenantId Environment
158+
------- ---------------- -------- -----------
159+
yyyy-yyyy-yyyy-yyyy Subscription1 xxxx-xxxx-xxxx-xxxx AzureCloud
160+
```
161+
162+
This command connects using the managed service identity of "myUserAssignedIdentity" by adding the User Assigned Identity to the Virtual Machine, then connecting using the Id of the User Assigned Identity.
163+
More information about configuring Managed Identities can be found here: https://docs.microsoft.com/en-us/azure/active-directory/managed-identities-azure-resources/qs-configure-powershell-windows-vm.
164+
165+
### Example 7: Add an account using certificates
137166
```powershell
138167
# For more information on creating a self-signed certificate
139168
# and giving it proper permissions, please see the following:
@@ -154,7 +183,26 @@ TenantId : 4cd76576-b611-43d0-8f2b-adcb139531bf
154183
Environment : AzureCloud
155184
```
156185

157-
This command connects to an Azure account using certificate-based service principal authentication. Theservice principal used for authentication should have been created with the given certificate.
186+
This command connects to an Azure account using certificate-based service principal authentication. The service principal used for authentication should have been created with the given certificate.
187+
188+
### Example 8: Add an account using AccessToken authentication
189+
```powershell
190+
PS C:\> $url = "https://login.windows.net/<TenantId>/oauth2/token"
191+
PS C:\> $body = "grant_type=refresh_token&refresh_token=<refreshtoken>" # Refresh token obtained from ~/.azure/TokenCache.dat
192+
PS C:\> $response = Invoke-RestMethod $url -Method POST -Body $body
193+
PS C:\> $AccessToken = $response.access_token
194+
PS C:\> $body1 = $body + "&resource=https%3A%2F%2Fvault.azure.net"
195+
PS C:\> $response = Invoke-RestMethod $url -Method POST -Body $body1
196+
PS C:\> $body2 = $body + "&resource=https%3A%2F%2Fgraph.windows.net"
197+
PS C:\> $GraphAccessToken = $response.access_token
198+
PS C:\> Connect-AzAccount -AccountId "[email protected]" -AccessToken $AccessToken -KeyVaultAccessToken $KeyVaultAccessToken -GraphAccessToken $GraphAccessToken -Tenant "xxxx-xxxx-xxxx-xxxx" -SubscriptionId "yyyy-yyyy-yyyy-yyyy"
199+
200+
Account SubscriptionName TenantId Environment
201+
------- ---------------- -------- -----------
202+
[email protected] Subscription1 xxxx-xxxx-xxxx-xxxx AzureCloud
203+
```
204+
205+
This command connects to an Azure account specified in "AccountId" using the AccessToken and KeyVaultAccessToken provided.
158206

159207
## PARAMETERS
160208

@@ -174,7 +222,8 @@ Accept wildcard characters: False
174222
```
175223
176224
### -AccountId
177-
Account Id for access token
225+
Account Id for access token in AccessToken parameter set.
226+
Account Id for managed service in ManagedService parameter set. Can be a managed service resource Id, or the associated client id. To use the SystemAssigned identity, leave this field blank.
178227
179228
```yaml
180229
Type: System.String

0 commit comments

Comments
 (0)