Script: Get Microsoft Teams phone numbers and where they are assigned

This PowerShell script which collects assigned and unassigned phone numbers from Microsoft Teams and shows you where they are used. The script supports Users, Meeting Rooms, Online Application Instances (Resource Accounts) and Dial-in Conference numbers.

The script can output the results to the console or to a CSV.

Example output:

Note: A version of my script that has been enhanced by Ruud van Strijp is available here. Extra features at the time of writing:

  • Changed login method and file save location. Added HTML export by default
  • Added UPN. Added HTML table width for better readability
  • Added EV columns; Calling and Voice Routing Policies
  • Changed for module 3.0.0
  • Get Dial Plan, fix first name, merge Resource Account and User, make table wider

Script

Andrew Morpeth
Andrew Morpethhttps://ucgeek.co/author/amorpeth/
Andrew is a Modern Workplace Consultant specialising in Microsoft technologies based in Auckland, New Zealand; Andrew is a Director and Professional Services Manager at Lucidity Cloud Services and a Microsoft MVP.

Related Articles

4 COMMENTS

  1. Great work! This script helped me to finally identify a phone number I couldn’t for the life of me find in the system. Exactly what I was looking for 🙂

    I did have to make a few tweaks though to get it to generate a complete list of phone numbers as I was hitting limits on the functions. Presumably you were working with a smaller dataset. Specifically:
    – Add ‘-All’ to the Get-MsolUser function
    – Turns out the Get-CsPhoneNumberAssignment only returns max 500 numbers, got around this by implementing the fix described here: https://robdy.io/all-available-numbers-calling-plan/

    I also set the csv path to where the script is executed from (as opposed to a static path) and fixed the misspellings on lines 86 and 92 (assigne -> assigned).

  2. This is great for listing all the assigned numbers within our system, as well as their AssignmentType.

    However, I’m struggling to find a functional method to yield abandoned/unassigned numbers within our Teams tenant.

    Two scenarios I can think of within our environment where this would be required. Eg:
    > Staff member has a DDI assigned within Microsoft Teams and uses it as their telephony solution.
    > Staff member leaves the company.
    > Account is disabled, causing the number to become orphaned.
    > Number is technically still within our Microsoft Teams Tenant, but not assigned to anyone and not yieldable via PowerShell scripts like this and other ones, as well as not being listed in the portal.
    > Requires us to write down the number somewhere so we know it exists and can be assigned to someone else in the future.

    It would be great if there’s an appropriate cmdlet to yield what numbers are within our Tenant but not assigned to any object to stop us having to maintain a list of numbers which aren’t assigned.

    Any ideas on this? Greatly appreciated.

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Andrew Morpeth
Andrew Morpethhttps://ucgeek.co/author/amorpeth/
Andrew is a Modern Workplace Consultant specialising in Microsoft technologies based in Auckland, New Zealand; Andrew is a Director and Professional Services Manager at Lucidity Cloud Services and a Microsoft MVP.

Latest Articles