Skip to content

Instantly share code, notes, and snippets.

@kfosaaen
Created March 8, 2023 22:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kfosaaen/e9a77a15ea7f26c05fd0f1a8ad85b0fd to your computer and use it in GitHub Desktop.
Save kfosaaen/e9a77a15ea7f26c05fd0f1a8ad85b0fd to your computer and use it in GitHub Desktop.
PowerShell 3-liner to find roles attached to your current user
# Get a token and split out the payload
$token = ((Get-AzAccessToken).Token).Split(".")[1].Replace('-', '+').Replace('_', '/')
# Add padding, if needed
while ($token.Length % 4) {$token += "="}
# Base64 Decode, convert from json, extract OID, pass into filter for Get-AzRoleAssignment to find current roles
Get-AzRoleAssignment | where ObjectId -EQ ([System.Text.Encoding]::ASCII.GetString([System.Convert]::FromBase64String($token)) | ConvertFrom-Json).oid
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment