Get all available user numbers in Calling Plans

By Robert Dyjas last month • Edit this post

From time to time we need to verify how many available numbers are there in your directory. Here's how to do it.

NOTE: The article below doesn't apply to numbers provided via Direct Routing

We'll use Teams PowerShell module. Connecting to Skype for Business Online is as usual:

$sfbSession = New-CsOnlineSession
Import-PSSession $sfbSession

NOTE: If you still use Skype for Business Online module, remember that it's being decomissioned. I have an article showing how to migrate to new module.

The cmdlet we'll be using is Get-CsOnlineTelephoneNumber:

$allNumbers = Get-CsOnlineTelephoneNumber -IsNotAssigned -ResultSize 2147483647 -InventoryType Subscriber

Parameters we use:

  • -IsNotAssigned - self explanatory
  • -ResultSize 2147483647 - there's no support for Unlimited, in contrary to other Microsoft 365 cmdlets, so we specify maximum value (based on the docs)
  • -InventoryType Subscriber - based on the docs, it's used to display numbers, which can be assigned to users.

Now we have our numbers saved into variable. We can process them, as we need.

Few examples:

# Group by city
$allNumbers | Group-Object CityCode -NoElement

# List all numbers
$allNumbers.Id

# Copy all numbers to clipboard
$allNumbers.Id | clip