Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save frankhu-2021/1305991696b084c120a757dc0694f49c to your computer and use it in GitHub Desktop.
Save frankhu-2021/1305991696b084c120a757dc0694f49c to your computer and use it in GitHub Desktop.
Returns users full name, email address, and azure role in your tenant and prints them out in a csv format. You need to connect-azuread first before running this powershell script.
$myuser = get-azaduser
$mygroups = get-azadgroup
$myReport = New-Object System.Collections.ArrayList($null)
$myReport.AddRange($myuser)
for($i =0; $i -lt $myuser.length; ++$i){
$fullname = $myuser.Get($i).displayname;
$emailaddress = $myuser.get($i).userprincipalname;
$azurerole = Get-AzRoleAssignment -ObjectId $myuser.Get($i).id
IF([string]::IsNullOrWhiteSpace($azurerole)) {
$azurerole = "No Roles";
}
$userDetails= $fullname + ' , ' + $emailaddress + ' , ' + $azurerole;
$myReport.Add($userDetails);
}
$myReport
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment