7 Must-Have Graph PowerShell Scripts to Manage Microsoft 365 Groups & Teams

Microsoft 365 Groups and Teams are central to collaboration — but without automation, managing them at scale becomes tedious. These Graph PowerShell scripts will help you create, manage, audit, and optimize your Groups and Teams effortlessly.

Below are 7 must-have scripts for every admin:

Create a Microsoft 365 Group

$params = @{
    displayName = "Project Falcon Team"
    mailEnabled = $true
    mailNickname = "projectfalcon"
    securityEnabled = $false
    groupTypes = @("Unified")
}

New-MgGroup -BodyParameter $params

Tip: Always validate that mailNickname is unique to avoid 400 errors.

Add Members to a Microsoft 365 Group (Bulk Member Addition via CSV)

CSV Template

CSV Template:
GroupId,UserId
group-guid-here,user-guid-1
group-guid-here,user-guid-2

$members = Import-Csv "AddGroupMembers.csv"
foreach ($entry in $members) {
    New-MgGroupMemberByRef -GroupId $entry.GroupId `
        -BodyParameter @{
            "@odata.id" = "https://graph.microsoft.com/v1.0/directoryObjects/$($entry.UserId)"
        }
}

Tip: Use Get-MgGroup and Get-MgUser to fetch IDs beforehand.


Remove a Member from a Group

Remove-MgGroupMemberByRef -GroupId "group-guid" -DirectoryObjectId "user-guid"

Useful for cleaning up access without deleting the group.


List All Archived Teams

$teams = Get-MgGroup -All -Filter "resourceProvisioningOptions/Any(x:x eq 'Team')" ` -Property Id, DisplayName

foreach ($team in $teams) {
    try {
        $teamDetails = Get-MgTeam -TeamId $team.Id
        if ($teamDetails.IsArchived -eq $true) {
            Write-Output "Archived Team: $($team.DisplayName) - ID: $($team.Id)"
        }
    } catch {
        Write-Output "Failed to fetch team details for $($team.DisplayName)"
    }
}

This script retrieves group-backed Teams and checks archival status safely.


Get Member Count for Each Team

$groups = Get-MgGroup -All -Filter "resourceProvisioningOptions/Any(x:x eq 'Team')" ` -Property Id, DisplayName

foreach ($group in $groups) {
    $members = Get-MgGroupMember -GroupId $group.Id
    $memberCount = ($members).Count
    Write-Output "$($group.DisplayName): $memberCount members"
}

Helps detect inactive or bloated teams.


List All Teams Without Owners (Orphaned Teams)

$teams = Get-MgGroup -All -Filter "resourceProvisioningOptions/Any(x:x eq 'Team')" ` -Property Id, DisplayName
foreach ($team in $teams) {
    $owners = Get-MgGroupOwner -GroupId $team.Id
    if (-not $owners) {
        Write-Output "Orphaned Team: $($team.DisplayName)"
    }
}

Teams without owners pose a governance risk. Assign one ASAP.

Export All Teams with Creation Date and Visibility

Get-MgGroup -All -Filter "resourceProvisioningOptions/Any(x:x eq 'Team')" `
            -Property DisplayName, CreatedDateTime, Visibility |
Select-Object DisplayName, CreatedDateTime, Visibility |
Export-Csv "TeamsReport.csv" -NoTypeInformation

Create monthly snapshots to track trends in Team creation and privacy settings.

Final Thoughts

These scripts give you control over group membership, visibility, ownership, and lifecycle management — all critical components of Microsoft 365 governance. Automate your daily admin load, and shift focus toward proactive Teams optimization and clean-up.

Did You Know? Managing Microsoft 365 applications is even easier with automation. Try our Graph PowerShell scripts to automate tasks like generating reports, cleaning up inactive Teams, or assigning licenses efficiently.

Ready to get the most out of Microsoft 365 tools? Explore our free Microsoft 365 administration tools to simplify your administrative tasks and boost productivity.

© Your Site Name. All Rights Reserved. Design by HTML Codex