Find free PhoneNumbers in Teams Direct Routing

I wrote this little function in powershell to list a specified number of free phone numbers in a range.

Example: Get-FreePhoneNumbers -NumberRangeLow 12340000 -NumberRangeHigh 12340100 -FreeNumbers 2

Parameter FreeNumbers defines how many free numbers you want to list. Default=1


function Get-FreePhoneNumbers {
    param (
        # List how many free numbers i.e. 10
        [parameter(Mandatory=$false,position=0)]
        [int]$FreeNumbers =1,

        # Enter the lower number of the numberrange
        [parameter(Mandatory=$false,position=0)]
        [int]$NumberRangeLow,

        # Enter the highest number of the numberrange
        [parameter(Mandatory=$false,position=0)]
        [int]$NumberRangeHigh

    )

        $range = $NumberRangeLow..$NumberRangeHigh
        $Lownumber ="47"+$NumberRangeLow
        $HighNumber ="47"+$NumberRangeHigh
        $PhoneNumbers=get-AssignedPSTNNumbers -NumberRangeLow $Lownumber -NumberRangeHigh $HighNumber | select phoneNumber
        $occupied=$PhoneNumbers.phonenumber.substring(7,8)
        $free=compare $range $occupied -PassThru | select-object -first $FreeNumbers
        write-host "Free Number(s)" $free
           
}

Comments

Post a Comment

Popular Posts