scripts/local/teams.ps1

<#
    Raidiness — Microsoft Teams (local, read-only)

    One question: is transcription enabled in the meeting policy. Without
    transcription there is no meeting recap in Copilot, however many licences
    there are.

    Role: Global Reader or Teams Reader. Get cmdlets only.
    Writes: nothing in the tenant.
    Output: JSON for the "Microsoft Teams" module.

    Usage:
      .\teams.ps1 -TenantId <tenant> -RunId <run> -OutputPath .\teams.json
#>


[CmdletBinding()]
param(
    [Parameter(Mandatory = $true)][string] $TenantId,
    [Parameter(Mandatory = $true)][string] $RunId,
    [string] $OutputPath = ".\raidiness-teams.json"
)

$ErrorActionPreference = "Stop"

Write-Host "Raidiness — Microsoft Teams, read-only. Role: Global Reader or Teams Reader." -ForegroundColor Cyan
Write-Host "Nothing will be changed in the tenant." -ForegroundColor Cyan

if (-not (Get-Module -ListAvailable -Name MicrosoftTeams)) {
    throw "The MicrosoftTeams module is missing. Install it first: Install-Module MicrosoftTeams -Scope CurrentUser"
}

Import-Module MicrosoftTeams
Connect-MicrosoftTeams -TenantId $TenantId | Out-Null

$policies = Get-CsTeamsMeetingPolicy |
    Select-Object Identity, AllowTranscription, AllowCloudRecording,
        AllowRecordingStorageOutsideRegion, AutoRecording, ChannelRecordingDownload,
        AllowCopilot, Copilot

Disconnect-MicrosoftTeams -Confirm:$false | Out-Null

$payload = [ordered]@{
    raidiness = [ordered]@{
        version     = "1.0"
        module      = "teams"
        tenantId    = $TenantId
        runId       = $RunId
        generatedAt = (Get-Date).ToUniversalTime().ToString("o")
        upnsHashed  = $true
    }
    results = [ordered]@{
        "teams.meetingPolicies" = @($policies)
    }
}

$payload | ConvertTo-Json -Depth 6 | Out-File -FilePath $OutputPath -Encoding utf8
Write-Host "Done. Upload $OutputPath in Raidiness under the Microsoft Teams module." -ForegroundColor Green