All scripts
Microsoft 365 293

Get-TeamsPhoneNumberInventory

Exports every phone number assigned in Teams Phone, who it is assigned to, and its usage type, so unused or misassigned numbers are easy to catch during a licensing review.

Get-TeamsPhoneNumberInventory.ps1
<#
.SYNOPSIS
    Exports Teams Phone number assignments.

.DESCRIPTION
    Lists every phone number in the tenant's phone number inventory,
    whether it is assigned, to whom, and its usage type, so unused or
    misassigned numbers show up clearly during a licensing or cost review.

.PARAMETER ExportPath
    Path to write the CSV to. Defaults to the current directory.

.EXAMPLE
    .\Get-TeamsPhoneNumberInventory.ps1

.NOTES
    Requires the MicrosoftTeams module and an active Connect-MicrosoftTeams session.

.AUTHOR
    Shehryar Hassan
#>

param(
    [string]$ExportPath = (Get-Location).Path
)

$numbers = Get-CsPhoneNumberAssignment

$report = $numbers | Select-Object TelephoneNumber, NumberType, AssignedPstnTargetId, ActivationState, IsoCountryCode

$file = Join-Path $ExportPath "teams-phone-inventory_$(Get-Date -Format yyyyMMdd_HHmmss).csv"
$report | Export-Csv -Path $file -NoTypeInformation

$unassigned = $report | Where-Object { -not $_.AssignedPstnTargetId }
Write-Host "$($report.Count) number(s) total, $($unassigned.Count) unassigned. Exported to $file" -ForegroundColor Cyan

Read it before you run it, and test in a safe tenant first.