Name, UPN, Status (Enabled/Disabed), Type (Member/Guest), Mailbox (User/Shared), Licenses
Connect-MgGraph -Scopes "User.Read.All","Organization.Read.All"
Connect-ExchangeOnline -ShowBanner:$false
# Officiƫle Microsoft-lijst met productnamen (licentie-ID > naam)
$csvUrl = 'https://download.microsoft.com/download/e/3/e/e3e9faf2-f28b-490a-9ada-c6089a1fc5b0/Product%20names%20and%20service%20plan%20identifiers%20for%20licensing.csv'
$ProgressPreference = "SilentlyContinue"
$resp = Invoke-WebRequest $csvUrl -UseBasicParsing
$names = @{}
[Text.Encoding]::UTF8.GetString($resp.RawContentStream.ToArray()) | ConvertFrom-Csv | ForEach-Object {
if ($_.GUID -and -not $names.ContainsKey($_.GUID)) { $names[$_.GUID] = $_.Product_Display_Name }
}
# Licenties in deze tenant; staat een licentie niet in de lijst, dan blijft de technische naam staan
$skus = @{}
Get-MgSubscribedSku -All | ForEach-Object {
$id = [string]$_.SkuId
$skus[$id] = if ($names.ContainsKey($id)) { $names[$id] } else { $_.SkuPartNumber }
}
# Mailboxtype per gebruiker (gekoppeld via object-ID)
$mailboxes = @{}
Get-EXOMailbox -ResultSize Unlimited -Properties RecipientTypeDetails | ForEach-Object {
if ($_.ExternalDirectoryObjectId) { $mailboxes[$_.ExternalDirectoryObjectId] = $_.RecipientTypeDetails }
}
Get-MgUser -All -Property Id,DisplayName,UserPrincipalName,AccountEnabled,UserType,AssignedLicenses |
Select-Object @{n='Name'; e={$_.DisplayName}},
@{n='UPN'; e={$_.UserPrincipalName}},
@{n='Status'; e={if ($_.AccountEnabled) {'Enabled'} else {'Disabled'}}},
@{n='Type'; e={$_.UserType}},
@{n='Mailbox'; e={if ($mailboxes.ContainsKey($_.Id)) { $mailboxes[$_.Id] } else { 'No mailbox' }}},
@{n='Licenses'; e={($_.AssignedLicenses | ForEach-Object { $skus[[string]$_.SkuId] }) -join '; '}} |
Sort-Object Name |
Export-Csv "$env:USERPROFILE\Downloads\microsoft-365-export.csv" -NoTypeInformation -Delimiter ';' -Encoding UTF8
Disconnect-ExchangeOnline -Confirm:$false
Disconnect-MgGraph