Jul 04 2022 10:18 AM
I am looking for PSTN and SMS usage teams report using PowerShell and export it into SharePoint list. Any advise ?
Thanks
Mar 07 2023 12:38 AM - last edited on Jun 28 2023 09:51 AM by Eric Starker
Mar 07 2023 12:38 AM - last edited on Jun 28 2023 09:51 AM by Eric Starker
You can use Microsoft Graph APIs to get the PSTN and SMS usage data for Teams. Here is an example PowerShell script to retrieve the PSTN and SMS usage data for a given time period and export it to a SharePoint list.
Connect-PnPOnline -Url "https://yourtenant.sharepoint.com/sites/yourSite" -Interactive
Connect-MicrosoftTeams
$startDate = (Get-Date).AddDays(-7).ToString("yyyy-MM-dd")
$endDate = (Get-Date).ToString("yyyy-MM-dd")
$usageData = Invoke-RestMethod -Method Get -Uri "https://graph.microsoft.com/beta/communications/callRecords?$filter=callType eq 'peerToPeer' and startDateTime ge $startDate and startDateTime le $endDate" -Headers @{Authorization = "Bearer $((Get-MicrosoftAccessToken).AccessToken)"}
You can then loop through the $usageData variable to extract the data you need, such as the phone number, call duration, and cost.
Finally, you can export the data to a SharePoint list using the Add-PnPListItem cmdlet. Here's an example:
$web = Get-PnPWeb
$list = Get-PnPList -Identity "Usage Data"
foreach ($data in $usageData) {
Add-PnPListItem -List $list -Values @{"Phone Number" = $data.resource.@from.phoneNumber; "Call Duration" = $data.resource.duration; "Cost" = $data.resource.cost.amount}
}
Note: The above code is just an example and may need to be modified to fit your specific requirements.
Source: (external link removed by moderator)
Mar 09 2023 08:41 AM - edited Mar 09 2023 08:44 AM
@davidlime160Thank you, let me test it out.
i see you have used a Url involving Microsoft Graph. Do i need any permissions beyond Teams admin to use this url. i have been using pnp but never used graph so just wondering?