Created
November 8, 2019 03:08
-
-
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$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