You can check how many numbers you have in your Teams Calling Plans. PowerShell cmdlet to use is Get-CsPhoneNumberAssignment.
In the example below, we'll list all the user numbers. We're only interested in the ones, which are available to assign. Therefore, we'll filter out the numbers already assigned.
The most frequent use-case for such listing will be to find out a number, which can be assigned to a new employee.
We'll use the Teams PowerShell module. Since version 2.0 the cmdlet for connecting is:
Connect-MicrosoftTeams
The cmdlet we used in the previous version of this article was Get-CsOnlineTelephoneNumber
. However, that one is currently decommissioned. Its replacement is Get-CsPhoneNumberAssignment
.
The set of parameters we need to use is:
$csPhoneNumberAssignmentParams = @{
CapabilitiesContain = 'UserAssignment'
NumberType = 'CallingPlan'
PstnAssignmentStatus = 'Unassigned'
}
$allNumbers = Get-CsPhoneNumberAssignment @csPhoneNumberAssignmentParams
Parameters we use:
The example above will return only the first 500 numbers. If we have a larger tenancy, we'd need to consider the fact that we might have more numbers available.
The new cmdlet doesn't have a ResultSize parameter we could use. We need to run the cmdlet in a loop using Top and Skip parameters. An example of how we can do that is shown below:
$skip = 0
$allNumbers = do {
$csPhoneNumberAssignmentParams = @{
CapabilitiesContain = 'UserAssignment'
NumberType = 'CallingPlan'
PstnAssignmentStatus = 'Unassigned'
Skip = $skip
}
$res = Get-CsPhoneNumberAssignment @csPhoneNumberAssignmentParams
$skip += 500
$res
} while ($res)
Now we have our numbers saved into a variable. We can process them, as we need.
Few examples:
# Count by country
$allNumbers | Group-Object IsoCountryCode -NoElement
# List all numbers
$allNumbers.TelephoneNumber
# Copy all numbers to clipboard
$allNumbers.TelephoneNumber | clip