From b40b54e2e4ebefc3608eaa0b9e5eda371b44340b Mon Sep 17 00:00:00 2001 From: Parker Shelton Date: Fri, 24 Oct 2025 16:59:22 -0700 Subject: [PATCH] Fix PowerShell command typos in VM token usage Updated PowerShell commands to use Invoke-RestMethod instead of Invoke-RestMeth for acquiring access tokens and retrieving VM information. --- .../how-to-use-vm-token.md | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/docs/identity/managed-identities-azure-resources/how-to-use-vm-token.md b/docs/identity/managed-identities-azure-resources/how-to-use-vm-token.md index 4aed58d023b..8ca22c660fa 100644 --- a/docs/identity/managed-identities-azure-resources/how-to-use-vm-token.md +++ b/docs/identity/managed-identities-azure-resources/how-to-use-vm-token.md @@ -291,27 +291,27 @@ The following example demonstrates how to use the managed identities for Azure r 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 ``, ``, and ``, respectively. ```azurepowershell -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"} +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"} ``` Example of how to parse the access token from the response: ```azurepowershell # Get an access token for managed identities for Azure resources $resource = 'https://management.azure.com' -$response = Invoke-RestMeth -Method GET ` - -Uri 'http://169.254.169.254/metadata/identity/oauth2/token?api-version=2018-02-01&resource=$resource' ` - -Headers @{ Metadata="true" } +$response = Invoke-RestMethod -Method GET ` + -Uri "http://169.254.169.254/metadata/identity/oauth2/token?api-version=2018-02-01&resource=$resource" ` + -Headers @{ Metadata="true" } $content = $response.Content | ConvertFrom-Json $accessToken = $content.access_token Write-Host "Access token using a User-Assigned Managed Identity is $accessToken" # Use the access token to get resource information for the VM $secureToken = $accessToken | ConvertTo-SecureString -AsPlainText -$vmInfoRest = Invoke-RestMeth -Method GET ` - -Uri 'https://management.azure.com/subscriptions//resourceGroups//providers/Microsoft.Compute/virtualMachines/?api-version=2017-12-01' ` - -ContentType 'application/json' ` - -Authentication Bearer ` - -Token $secureToken +$vmInfoRest = Invoke-RestMethod -Method GET ` + -Uri 'https://management.azure.com/subscriptions//resourceGroups//providers/Microsoft.Compute/virtualMachines/?api-version=2017-12-01' ` + -ContentType 'application/json' ` + -Authentication Bearer ` + -Token $secureToken Write-Host "JSON returned from call to get VM info: $($vmInfoRest.content)" ```