Microsoft recently released the ability to programmatically retrieve Microsoft Teams PSTN Usage records using the Graph API. This data is currently available in the Teams admin center under Analytics & reports > Usage reports > PSTN & SMS usage. However, performing additional analysis on the data required manually exporting to a CSV file, and who wants to do that?
Enter the TeamsCloudCommunicationApi module.
Inspired by Lee Ford’s Get-TeamsPSTNCallRecords script, I wrote my own module to work with the Microsoft Teams Graph API to retrieve PSTN records. I approached the solution a bit differently:
- Ability to create and use a Graph API access token without storing client secret in the script
- Separate commands for retrieving calling plan and direct routing call records
- Use Export-Csv or ConvertTo-Json to export the data to the format you want. Or just let it output to the console window.
- Specify Start and End dates or the last number of days to retrieve records
Check out the module code and some how-to instructions on setting up the Azure application registration, importing the module, and some example commands:
You can download the module directly from the PowerShell Gallery using the following command:
Install-Module -Name TeamsCloudCommunicationApi
Here is the module in action retrieving records based on a date range. The Get-TeamsPstnCalls retrieves all properties of the call including start and end times, duration in seconds, and caller/callee numbers.
This Graph API is currently under beta and not recommended for production, so use it at your own risk. You can find more information on the Cloud Communication API here:
Microsoft Docs: Working with communications API in Microsoft Graph
Questions or comments? If so, drop me a note below or find me on Twitter or LinkedIn to discuss further.
Interested in an automated solution? Check out my article How to Export Teams PSTN Usage Records with Azure Functions!