Filtering shared mailboxes from MgUser results

Jon Covey 0 Reputation points
2025-05-01T23:20:59.4466667+00:00

I have a tenant that has multiple brands, with each brand denoted by a domain. I am trying to put together a script to list the licenses for each user, including their brand name. This has been successful so far.

The only thing I can't figure out is how to filter out the shared mailboxes from the get-MgUser list to apply the rest f the script to.

Below is what I have, and it breaks when I add the filter to the get-mguser prompt. Without the filter, it works, but includes all mailboxes.

Error received when running code block:

"Get-MgUser_List: Property 'mailboxtype' does not exist as a declared property or extension property."

Connect-MgGraph -Scope User.Read.All
$Users = Get-MgUser -filter "mailboxtype ne 'shared'" -All 
$output = @()
$domain = ""
$brand = ""
$location = ""
$locations = @()
$brands = @()
$Licenses = ""
$brandusers = ""


$users | ForEach-Object {

    $domain=($_.UserPrincipalName -split"@")[1]
    $brand = ($domain -split "\.")[0]
    $location=Get-MgUser -userid $_.UserPrincipalName -Property Department | select Department
    $Licenses=get-mguserlicensedetail -userid $_.UserPrincipalName | select SkuPartNumber
    #echo $Licenses

PowerShell
PowerShell
A family of Microsoft task automation and configuration management frameworks consisting of a command-line shell and associated scripting language.
2,924 questions
0 comments No comments
{count} votes

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.