Skip to content

Commit 186aabc

Browse files
authored
Merge pull request #1739 from HarryGwinnell/main
Fix Powershell Cmdlet name in `How to use VM Tokens`
2 parents 573236f + 2255aa2 commit 186aabc

File tree

1 file changed

+5
-6
lines changed

1 file changed

+5
-6
lines changed

docs/identity/managed-identities-azure-resources/how-to-use-vm-token.md

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -291,23 +291,22 @@ The following example demonstrates how to use the managed identities for Azure r
291291
2. Use the access token to call an Azure Resource Manager REST API and get information about the VM. Be sure to substitute your subscription ID, resource group name, and virtual machine name for `<SUBSCRIPTION-ID>`, `<RESOURCE-GROUP>`, and `<VM-NAME>`, respectively.
292292

293293
```azurepowershell
294-
Invoke-RestMeth -Method GET -Uri 'http://169.254.169.254/metadata/identity/oauth2/token?api-version=2018-02-01&resource=https%3A%2F%2Fmanagement.azure.com%2F' -Headers @{Metadata="true"}
294+
Invoke-RestMethod -Method GET -Uri 'http://169.254.169.254/metadata/identity/oauth2/token?api-version=2018-02-01&resource=https%3A%2F%2Fmanagement.azure.com%2F' -Headers @{Metadata="true"}
295295
```
296296

297297
Example of how to parse the access token from the response:
298298
```azurepowershell
299299
# Get an access token for managed identities for Azure resources
300300
$resource = 'https://management.azure.com'
301-
$response = Invoke-RestMeth -Method GET `
302-
-Uri 'http://169.254.169.254/metadata/identity/oauth2/token?api-version=2018-02-01&resource=$resource' `
301+
$response = Invoke-RestMethod -Method GET `
302+
-Uri "http://169.254.169.254/metadata/identity/oauth2/token?api-version=2018-02-01&resource=$resource" `
303303
-Headers @{ Metadata="true" }
304-
$content = $response.Content | ConvertFrom-Json
305-
$accessToken = $content.access_token
304+
$accessToken = $response.access_token
306305
Write-Host "Access token using a User-Assigned Managed Identity is $accessToken"
307306
308307
# Use the access token to get resource information for the VM
309308
$secureToken = $accessToken | ConvertTo-SecureString -AsPlainText
310-
$vmInfoRest = Invoke-RestMeth -Method GET `
309+
$vmInfoRest = Invoke-RestMethod -Method GET `
311310
-Uri 'https://management.azure.com/subscriptions/<SUBSCRIPTION-ID>/resourceGroups/<RESOURCE-GROUP>/providers/Microsoft.Compute/virtualMachines/<VM-NAME>?api-version=2017-12-01' `
312311
-ContentType 'application/json' `
313312
-Authentication Bearer `

0 commit comments

Comments
 (0)