Powershell script not giving me all users in M365 Group

I am trying to pull our users from a M365 group and export the results into an excel file. It worked fine in the past. However, it will not display everyone in the group now. Almost like it stops short. I have a theory that it is because of the number of users in the group, which is 105.

My other team members have tried to run the script and they have also gotten the same results. Here is the script for reference:

$output = @()

$users = Get-AzureADGroupMember -ObjectId 563cf69d-cae5-4630-9705-9345a2ce1259

foreach ($user in $users) {
    $manager = Get-AzureADUserManager -ObjectId $user.ObjectId

    $data = New-Object -TypeName psobject

    $data | Add-Member -MemberType NoteProperty -Name Name -Value $user.DisplayName
    $data | Add-Member -MemberType NoteProperty -Name JobTitle -Value $user.JobTitle
    $data | Add-Member -MemberType NoteProperty -Name Manager -Value $manager.DisplayName
    $data | Add-Member -MemberType NoteProperty -Name Department -Value $user.Department 
    $data | Add-Member -MemberType NoteProperty -Name Mail -Value $user.Mail
    $data | Add-Member -MemberType NoteProperty -Name Mobile -Value $user.Mobile
    $data | Add-Member -MemberType NoteProperty -Name Number -Value $user.TelephoneNumber

    $output += $data


$output | Format-Table
$output | Export-Csv -Path 'C:\Users\EverettScott\OneDrive - ClimeCo\Desktop\GroupOrgInfo.csv'

Any feedback would be appreciated.


  • The answer is fairly simple, you're just missing the -All parameter:


    If true: Return all group members.

    If false: Return the number of objects specified by the Top parameter. If the top parameter is not specified, return the first 100 group members.

    So, this should solve your problem:

    $users = Get-AzureADGroupMember -ObjectId 563cf69d-cae5-4630-9705-9345a2ce1259 -All $true

    You should really consider migrating your code to the Microsoft.Graph Module, the AzureAD Module is deprecated and the API it's calling behind the scenes will no longer work in the future. See Important: Azure AD Graph Retirement and Powershell Module Deprecation for more information.

    This is how your code would look using the newer module:

    $members = Get-MgGroupMember -GroupId 563cf69d-cae5-4630-9705-9345a2ce1259 -All
    $members | ForEach-Object {
        $properties = $_.AdditionalProperties
        if ($properties['@odata.type'] -eq '#microsoft.graph.user') {
            $getMgUserSplat = @{
                UserId         = $_.Id
                Select         = 'department', 'mobilePhone', 'businessPhones', 'manager'
                ExpandProperty = 'manager'
            $user = Get-MgUser @getMgUserSplat
                Name       = $properties['displayName']
                JobTitle   = $properties['jobTitle']
                Manager    = $user.Manager.AdditionalProperties['displayName']
                Department = $user.Department
                Mail       = $properties['mail']
                Mobile     = $user.MobilePhone
                Number     = $user.BusinessPhones -join ', '
    } | Export-Csv 'C:\Users\EverettScott\OneDrive - ClimeCo\Desktop\GroupOrgInfo.csv'