$User = “user@tenant.onmicrosoft.com”
#$User = Read-host “Please enter Office365 Admin User name username@domain.onmicrosoft.com. “
$Creds = Get-Credential
#Connect-SPOService -Url https://tenant-admin.sharepoint.com -Credential $Creds
Connect-MsolService -Credential $Creds
$AllUserRoles = @()
$Users = Get-MsolUser -All
foreach($user in $Users)
{
$UserRoles = Get-MsolUserRole -UserPrincipalName $User.UserPrincipalName
foreach($role in $UserRoles)
{
$aRole = New-Object PSObject
$UserName = $User.UserPrincipalName
$RoleName = $role.Name.ToString()
Add-Member -input $aRole noteproperty ‘UserName’ $UserName
Add-Member -input $aRole noteproperty ‘RoleName’ $RoleName
$AllUserRoles += $aRole
}
}
$AllUserRoles | export-csv -Path C:\Scripts\SPOUserRoles.csv -NoTypeInformation -Force