Last active
April 26, 2025 10:19
-
-
Save ievgen-pavlenko/40a6d5d9c78af3715cc586b19907a3df to your computer and use it in GitHub Desktop.
Managed Identity Demo Script for Azure VM Environment
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#User Assigned Managed Identity | |
$clientId = 'xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx' | |
$resourceUri = 'https://management.azure.com/' | |
$uri = "http://169.254.169.254/metadata/identity/oauth2/token?api-version=2018-02-01&client_id=$clientId&resource=$resourceUri" | |
$response = Invoke-WebRequest -Uri $uri -Method GET -Headers @{Metadata="true"} | |
$content = $response.Content | ConvertFrom-Json | |
$content.access_token | |
#System Assigned Managed Identity | |
$resourceUri = 'https://management.azure.com/' | |
$uri = "http://169.254.169.254/metadata/identity/oauth2/token?api-version=2018-02-01&resource=$resourceUri" | |
$response = Invoke-WebRequest -Uri $uri -Method GET -Headers @{Metadata="true"} | |
$content = $response.Content | ConvertFrom-Json | |
$content.access_token |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment