Skip to content

Instantly share code, notes, and snippets.

@ciphertxt
Created May 10, 2016 12:43
Show Gist options
  • Star 12 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save ciphertxt/2036e614edf4bf920796059017fbbc3d to your computer and use it in GitHub Desktop.
Save ciphertxt/2036e614edf4bf920796059017fbbc3d to your computer and use it in GitHub Desktop.
Retrieves a list of current roles and the associated role members in an Office 365 tenant.
Import-Module MSOline -EA 0
Connect-MsolService -Credential (Get-Credential)
$admins=@()
$roles = Get-MsolRole
foreach ($role in $roles) {
$roleUsers = Get-MsolRoleMember -RoleObjectId $role.ObjectId
foreach ($roleUser in $roleUsers) {
$roleOutput = New-Object -TypeName PSObject
$roleOutput | Add-Member -MemberType NoteProperty -Name RoleMemberType -Value $roleUser.RoleMemberType
$roleOutput | Add-Member -MemberType NoteProperty -Name EmailAddress -Value $roleUser.EmailAddress
$roleOutput | Add-Member -MemberType NoteProperty -Name DisplayName -Value $roleUser.DisplayName
$roleOutput | Add-Member -MemberType NoteProperty -Name isLicensed -Value $roleUser.isLicensed
$roleOutput | Add-Member -MemberType NoteProperty -Name RoleName -Value $role.Name
$admins += $roleOutput
}
}
$admins | Export-Csv -NoTypeInformation ~\Downloads\Crowley365RolesUsers.csv
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment