This document provides a cmdlet best practice for supporting Managed Identity in Azure PowerShell.
- New cmdlets are required to follow the best practices. If any further discussion is needed, please contact [Azure PowerShell team](mailto: [email protected]);
- For existing cmdlets, we are strongly recommended to keep aligned with the best practice. Please contact [Azure PowerShell team](mailto: [email protected]) to make a proper migration plan.
Resources supported Managed Identity in management plane with common type definition in managedidentity.json.
Use [EnableSystemAssignedIdentity <SwitchParameter>]
to enable system-assigned identity and [UserAssignedIdentity <string[]>]
to add user-assigned identities.
New-AzResource ... -EnableSystemAssignedIdentity -UserAssignedIdentity <id1>, <id2>
- If
EnableSystemAssignedIdentity
is present, IdentityType is set up asSystemAssigned
, which enables system-assigned identity; - If
UserAssignedIdentity
is provided, IdentityType is set up asUserAssigned
, which adds user-assigned identities by provided value; - If
EnableSystemAssignedIdentity
andUserAssignedIdentity
both are not presented, IdentityType is set up asNone
; - If
EnableSystemAssignedIdentity
is present andUserAssignedIdentity
is provided, IdentityType is set up asSystemAssigned,UserAssigned
, which enables system-assigned identity and adds user-assigned identities by provided value;
Use [EnableSystemAssignedIdentity <bool>]
to enable or disable system-assigned identity and [UserAssignedIdentity <string[]>]
to set user-assigned identities.
Update-AzResource ... -EnableSystemAssignedIdentity $false
If EnableSystemAssignedIdentity
is provided, $false disables system-assigned identity and $true enables system-assigned identity. If EnableSystemAssignedIdentity
is not provided, it means no change happens on system-assigned identity.
Update-AzResource ... -UserAssignedIdentity <id1>, <id2>
If UserAssignedIdentity
is provided, user-assigned identities will be overridden as the value of UserAssignedIdentity
; If UserAssignedIdentity
is not provided, it means keep user-assigned identity as previous value.
Update-AzResource ... -UserAssignedIdentity @()
Especially, setting UserAssignedIdentity
as empty collection removes all existing user-assigned identities.
The design practices of Set- Cmdlet depends on if cmdlet will set properties that are not provided as empty or default value,
- If yes, please follow New- Cmdlet Design Practices;
- Otherwise, please follow Update- Cmdlet Design Practices.
Please contact [Azure PowerShell team](mailto: [email protected]) to make a proper migration plan.
Is it required to set the type of UserAssignedIdentity as string array if service only supports one user assigned identity?
We are recommended to use string array as the type of UserAssignedIdentity with following reasons:
- string array matches the swagger definition of
UserAssignedIdentity
; - string array is inclusive of a single string;
- No syntax changes if service supports one more user assigned identity in future;
- Service will provide correct error response if customer reaches the count limitation of
UserAssignedIdentity
ideally, which means no harm.