From 44afbec52762cb326f24c2c846ba3d69e0a4380f Mon Sep 17 00:00:00 2001 From: Harry Gwinnell Date: Mon, 1 Sep 2025 09:41:18 +0100 Subject: [PATCH 1/3] Fix Powershell Function name --- .../how-to-use-vm-token.md | 6 +++--- 1 file changed, 3 insertions(+), 3 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..c0156c6b073 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,14 +291,14 @@ 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 ` +$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 @@ -307,7 +307,7 @@ 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 ` +$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 ` From fe924a4558e7012c97489153b52903c16cabc07c Mon Sep 17 00:00:00 2001 From: Harry Gwinnell Date: Mon, 1 Sep 2025 09:48:36 +0100 Subject: [PATCH 2/3] Update how-to-use-vm-token.md --- .../managed-identities-azure-resources/how-to-use-vm-token.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 c0156c6b073..a7c36ead9d3 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 @@ -299,7 +299,7 @@ Example of how to parse the access token from the response: # Get an access token for managed identities for Azure resources $resource = 'https://management.azure.com' $response = Invoke-RestMethod -Method GET ` - -Uri 'http://169.254.169.254/metadata/identity/oauth2/token?api-version=2018-02-01&resource=$resource' ` + -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 From 2255aa21e340922a7ed010358259ddf93b29502c Mon Sep 17 00:00:00 2001 From: Harry Gwinnell Date: Mon, 1 Sep 2025 09:57:25 +0100 Subject: [PATCH 3/3] Simplify access token retrieval for VM identity --- .../managed-identities-azure-resources/how-to-use-vm-token.md | 3 +-- 1 file changed, 1 insertion(+), 2 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 a7c36ead9d3..388007446b0 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 @@ -301,8 +301,7 @@ $resource = 'https://management.azure.com' $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 +$accessToken = $response.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