Skip to content

Instantly share code, notes, and snippets.

@njmulsqb
Forked from kfosaaen/AppRegRoleFinder.ps1
Last active June 5, 2025 06:44
Show Gist options
  • Save njmulsqb/536e052aec5aa3d1f3f28fd5bdc1eb7e to your computer and use it in GitHub Desktop.
Save njmulsqb/536e052aec5aa3d1f3f28fd5bdc1eb7e to your computer and use it in GitHub Desktop.
PowerShell 3-liner to find roles attached to your current user
# Get token in system.security.securestring format and decode it
$securestring = (Get-AzAccessToken).token
$bstr = [System.Runtime.InteropServices.Marshal]::SecureStringToBSTR($secureString)
$plaintext = [System.Runtime.InteropServices.Marshal]::PtrToStringAuto($bstr)
$token = $plaintext.Split(".")[1].Replace('-', '+').Replace('_', '/')
while ($token.Length % 4) {$token += "="}
# Decode the token, and match the ObjectIds returned by Get-AzRoleAssignment with oid section of JWT. You can also manually decode the JWT and pass oid to Get-AzRoleAssignment -ObjectId $oid
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