Skip to content

Instantly share code, notes, and snippets.

@yamakadi
yamakadi / AppRegRoleFinder.ps1
Created June 21, 2024 10:04 — forked from kfosaaen/AppRegRoleFinder.ps1
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