It's about a year late, but I was looking for exactly this. I never found something that worked so built my own solution. I will describe the necessary parts, but won't give working code. I'm not that good at scripting haha.
First of all, you need certain MS Graph API permissions that are Application ONLY. (sigh @microsoft) This means you have to create an App registration in Azure with the required permissions and use grant admin consent. Then create a secret and then use this to gain access. Everything else won't work and will give you a 403 forbidden.
The permission needed is CallRecords.Read.All. This, as stated before, is an MS Graph Application permission and needs admin consent.
It could be you require CallRecord-PstnCalls.Read.All, I didn't but added it anyway for future scripting.
The PS module required is a subset of the Graph module:
Load-Module -Module "Microsoft.Graph.CloudCommunications"
(I expect Graph to be installed, I have my own code for checking this)
As Иван Бобров said, you, of course, also have to connect to MS Graph, but tbh, if you didn't knew this, you shouldn't be here IMO. Also, don't forget to Disconnect-MgGraph
afterwards.
I had to use two parts to get all my info.
- to get all records filtered with a start date\time (more filters are availble)
$results = Invoke-MGGraphRequest -Method get -Uri 'https://graph.microsoft.com/v1.0/communications/callRecords?$filter=startDateTime ge 2024-08-09T06:00:00Z' -OutputType PSObject
Important!!! This has 'pagination'. If it holds a lot of records, it will NOT show you everything. You will have to look if there is a object-member present called "@odata.nextLink" and use THAT link for the next set. Loop through all those links until the member no longer present.
Every GET will only get you the next 'page' of data.
- to get specifics from each gotten record, per $id.
Use this to get the $id from the $results, as per above, for a foreach-loop: ($results.value).id
$callRecord = Get-MgCommunicationCallRecord -CallRecordId $id -ExpandProperty "sessions(`$expand=segments)"
NOTE! the -ExpandedProperty and everything after is NOT required if you only the date\time and such. I needed it because the caller and callee usernames is part of the 'sessions' property. You can just leave it in if you don't give a.
Hopefully this will be useful to someone.
Regards.