How do I retrieve MS Teams phone numbers using Powershell MgGraph

Francisco Rivera 0 Reputation points
2024-09-19T22:58:45.92+00:00

Hi,

I am trying to automate the export of all our organization's teams numbers using Powershell. If I do it interactively, I am able to connect to MgGraph, run the command, "Get-CsPhoneNumberAssignment" and retrieve the information. However, when I try to automate it, I get "Access Denied". I can successfully use application authentication to connect to both MgGraph and Microsoft teams using the following: "Connect-MgGraph -TenantId $tenantId -ApplicationId $appId -CertificateThumbprint $thumbprint". Thinking that it's an API permission issue, I've granted every permission I can think of:

User's image

However, I keep getting the same error:

Welcome To Microsoft Graph!

Get-CsPhoneNumberAssignment : Access Denied.

At C:\FindFreeTeamsPhoneNumbers\RetrieveUsedPhoneNumbers.ps1:10 char:1

  • Get-CsPhoneNumberAssignment #-activationstate Activate | select Tele ...
  • 
        + CategoryInfo          : InvalidOperation: ({ TelephoneNumb...p = , Skip =  }:<>f__AnonymousType56`17) [Get-CsPhoneNumberAssignment_Get], RestException`1
    
        + FullyQualifiedErrorId : Forbidden,Microsoft.Teams.ConfigAPI.Cmdlets.Generated.Cmdlets.GetCsPhoneNumberAssignment_Get
    
    

Is there a particular API permission I need to add. Or does the MgGraph not support the retrieval of this information? I'm at a loss. Thank you for any info you can provide.

Microsoft Teams
Microsoft Teams
A Microsoft customizable chat-based workspace.
10,311 questions
Microsoft Graph
Microsoft Graph
A Microsoft programmability model that exposes REST APIs and client libraries to access data on Microsoft 365 services.
12,273 questions
PowerShell
PowerShell
A family of Microsoft task automation and configuration management frameworks consisting of a command-line shell and associated scripting language.
2,596 questions
{count} votes

1 answer

Sort by: Most helpful
  1. Hitesh Pachipulusu - MSFT 3,000 Reputation points Microsoft Vendor
    2024-09-20T06:48:17.1433333+00:00

    Hello Francisco Rivera,

    Thank you for contacting Microsoft Support!

    The Get-CsPhoneNumberAssignment cmdlet is a Teams PowerShell command, not a Graph PowerShell command. To use Get-CsPhoneNumberAssignment, you must have admin credentials; otherwise, you will encounter an access denied error.

    Currently, there is no Graph API endpoint available for retrieving Teams phone numbers. Please check the Q&A.

    I would recommend you submit this feature request using this support link, which will be monitored by Microsoft team and make the enhancements to Graph API.

    Hope this helps.

    If the answer is helpful, please click Accept Answer and kindly upvote it. If you have any further questions about this answer, please click Comment.


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.