I recently received helpful guidance on enabling both system-assigned
and user-assigned managed identities for an Azure Virtual Machine (VM)
through REST API calls. Now, I’m seeking assistance to replicate this process using PowerShell’s Invoke-RestMethod.
Here’s the REST API call I used to achieve this:
PATCH https://management.azure.com/subscriptions/<SUBSCRIPTION
ID>/resourceGroups/<RESOURCE
GROUP>/providers/Microsoft.Compute/virtualMachines/<VM
NAME>?api-version=2017-12-01 HTTP/1.1
{
"identity":{
"type":"SystemAssigned,UserAssigned",
"identityIds":[
"/subscriptions/<SUBSCRIPTION ID>/resourcegroups/<RESOURCE
GROUP>/providers/Microsoft.ManagedIdentity/userAssignedIdentities/<USER
ASSIGNED IDENTITY NAME>"
]
}
}
Could someone assist me in translating this into a PowerShell script
using Invoke-RestMethod? Specifically, I need guidance on how to
incorporate the authentication using a service principal, constructing
the JSON payload, and making the PATCH request.
Any help or examples would be greatly appreciated. Thank you!