Getting list of calls in Microsoft.Graph.CloudCommunications via powershell

Roman Korchak 16 Reputation points
2023-06-08T09:40:53.59+00:00

Hi All

I am trying to get some Teams Calls logs and came across Get-MgCommunicationCallRecord powershell command, which requires call id.

So the question is - how do I get a list of calls to get those call IDs via GraphAPI from powershell?

Thanks

Windows for business Windows Server User experience PowerShell
0 comments No comments
{count} votes

2 answers

Sort by: Most helpful
  1. Eric R 26 Reputation points
    2024-08-09T07:28:04.15+00:00

    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.

    1. 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.

    1. 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.

    1 person found this answer helpful.
    0 comments No comments

  2. Limitless Technology 44,751 Reputation points
    2023-06-09T12:50:12.9+00:00
    Hello Roman,
    
    Thank you for your question and for reaching out with your question today.
    
    To retrieve a list of call records and their IDs using Microsoft Graph API from PowerShell, you can follow these steps:
    
    1. Install the required modules: Install the PowerShell modules for Microsoft Graph API and Azure AD authentication. You can install them using the following commands:
    
    Install-Module -Name PowerShellGet -Force -AllowClobber -SkipPublisherCheck
    Install-Module -Name AzureAD
    Install-Module -Name Microsoft.Graph
    
    2. Connect to your Microsoft 365 account: Use the following command to connect to your Microsoft 365 account using Azure AD authentication:
    
    Connect-AzureAD
    
    3. Retrieve a list of call records: Use the Microsoft Graph API's `/communications/callRecords` endpoint to fetch the call records. Here's an example command:
    
    $callRecords = Invoke-GraphRequest -Uri 'https://graph.microsoft.com/v1.0/communications/callRecords'
    
    This command will retrieve all the call records available for your account. You can add query parameters to filter the results based on your requirements, such as specific dates, users, or call types.
    
    4. Process the call records: Once you have the call records, you can iterate through them to retrieve the call IDs. Here's an example:
    
    foreach ($callRecord in $callRecords.value) {
        $callId = $callRecord.id
        # Process the call ID as needed
        Write-Host "Call ID: $callId"
    }
    
    You can access other properties of the call record object as well, such as participants, start time, end time, etc., based on your requirements.
    
    I used AI provided by ChatGPT to formulate part of this response. I have verified that the information is accurate before sharing it with you.
    
    If the reply was helpful, please don’t forget to upvote or accept as answer.
    
    Best regards.
    

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.