Workloads/Get-TeamsUsage.ps1

# Get-TeamsUsage.ps1
# Collects 180-day Teams user activity via the Graph Reports API.
# Part of the M365-QuickAssess module -- not exported.

function Get-TeamsUsage
{
    param
    (
        $Assessment
    )

    Write-Log "Collecting Teams activity data (180 days)"

    try
    {
        $teams = Get-GraphReportCsv `
            -Uri "https://graph.microsoft.com/v1.0/reports/getTeamsUserActivityUserDetail(period='D180')"

        if ( -not $teams -or $teams.Count -eq 0 )
        {
            Write-Log "Teams activity report returned no data" "WARN"
            $Assessment.Teams.ActiveUserCount = $null
            return
        }

        $activeCount   = ( $teams | Where-Object { $_."Last Activity Date" } ).Count
        $inactiveCount = $teams.Count - $activeCount

        $Assessment.Teams.ActiveUserCount = $activeCount

        Write-Log "Teams (180 days): Active=$activeCount Inactive=$inactiveCount"

        # -------------------------------------------------------------------
        # Finding: Low Teams adoption
        # -------------------------------------------------------------------
        if ( $teams.Count -gt 0 )
        {
            $activePercent = [math]::Round( ( $activeCount / $teams.Count ) * 100, 0 )

            if ( $activePercent -lt 40 )
            {
                $Assessment.Findings += New-Finding `
                    -Type           "LowTeamsAdoption" `
                    -Summary        "Only $activePercent% of users have been active in Teams in the last 180 days" `
                    -Category       "Teams" `
                    -Severity       "Info" `
                    -Impact         "Low Teams adoption may indicate the tenant relies on alternative collaboration tools." `
                    -Recommendation "Confirm primary collaboration platform with the customer before scoping Teams migration."
            }
        }
    }
    catch
    {
        Write-Log "Teams activity collection failed: $( $_.Exception.Message )" "ERROR"
    }
}