Script for å finne ledige telefonnummer i Lync.

Det er ingen standard funksjonalitet innebygd i Lync for å finne tilgjengelige telefonnummer. Ståle Hansen i Atea har laget et script som henter ut ledige telefonnummer i alle nummerserier. Vi har nå testet dette og det vil bli et nyttig verktøy fremover.

  • Script ser ut som vist under og lagres i en .ps1 fil på Lync frontend server.
  • Start Lync management shell og gå til område hvor script er lagret. Start deretter med .\List_UnusedNumbers.ps1
  • Hver nummerserie vil bli listet opp og du ser antall nummer ledig. Hvilke nummer som er ledig kommer opp hvis du skriver inn bokstaven L

Ønsker å gi Ståle Hansen en stor takk. Under finner dere script, men for ytterligere informasjon se hans blog her

Script:

####################################################################################################
# List-UnusedNumbers.ps1
#
# v10 April 2011 by Ståle Hansen, Lync MVP (http://msunified.net)
#
# Thanks to Marjus Sirvinsks (http://marjuss.wordpress.com) for pointing me in the right direction
#
####################################################################################################
[System.Console]::ForegroundColor = [System.ConsoleColor]::White
clear-host

Write-Host «Script for finding unused numbers in Lync Server 2010, by Ståle Hansen»
Write-Host

foreach ($Serie in (Get-CsUnassignedNumber)) {

#The CountryCodeLength is the length of you countrycode. For Norway this is 47 so the length is 2.
#If you want to remove more than 2 digits, change the $CountryCodeLength
$CountryCodeLength=2
#The «tel:+» string is the +5 lenght that is added in the next line
$CountryCodeLength=$CountryCodeLength+5

#Now we get the replace string so that all numbers can be converted to an int
#In the norwegian case this value becomes tel:+47
$ReplaceValue=($Serie.NumberRangeStart).Substring(0,$CountryCodeLength)

#Check to see if Unassigned Numbers are in E.164 format, if its not, continue to the next number serie
if (($ReplaceValue.Substring(0,5)) -ne «tel:+»){
Write-Host «The script requires that Unassigned Numbers are populated in E.164 format» -Foregroundcolor Yellow
Write-Host «It appears that the number range » -nonewline
Write-Host $Serie.Identity -nonewline -Foregroundcolor Green
Write-Host » is not in this format»
Write-Host
Continue
}

#To see what your $ReplaceValue is, untag the next line
#Write-Host Value to be replaced is $ReplaceValue

$NumberStart=$Serie.NumberRangeStart | ForEach-Object {$_.Replace($ReplaceValue, «»)}
$NumberEnd=$Serie.NumberRangeEnd | ForEach-Object {$_.Replace($ReplaceValue, «»)}

$Ser=$NumberStart..$NumberEnd

$ErrorActionPreference = ‘SilentlyContinue’

$Used=Get-CsUser -Filter {LineURI -ne $Null} | Select-Object LineURI | out-string -stream
$Used+=Get-CsUser -Filter {PrivateLine -ne $Null} | Select-Object PrivateLine | out-string -stream
$Used+=Get-CsAnalogDevice -Filter {LineURI -ne $Null} | Select-Object LineURI | out-string -stream
$Used+=Get-CsCommonAreaPhone -Filter {LineURI -ne $Null} | Select-Object LineURI | out-string -stream
$Used+=Get-CsExUmContact -Filter {LineURI -ne $Null} | Select-Object LineURI | out-string -stream
$Used+=Get-CsDialInConferencingAccessNumber -Filter {LineURI -ne $Null} | Select-Object LineURI | out-string -stream
$Used+=Get-CsTrustedApplicationEndpoint -Filter {LineURI -ne $Null} | Select-Object LineURI | out-string -stream
$Used+=Get-CsRgsWorkflow | Select-Object LineURI | out-string -stream
$Used=$Used | ForEach-Object {$_.ToLower()}
$Used=$Used | ForEach-Object {$_.Replace($ReplaceValue, «»)}
$Used=$Used | ForEach-Object {$_.split(‘;’)[0]}

$ErrorActionPreference = ‘Continue’

$AllUsed=@()
foreach($Series in $Ser){foreach($UsedNumber in $Used){
if($Series -eq $UsedNumber){$AllUsed+=$UsedNumber}
}
}

$ListUnUsed=@()
$ComparisonResult=compare-object $Ser $AllUsed
foreach($UnUsed in $ComparisonResult){
if($UnUsed.SideIndicator -eq ‘<=’){$ListUnUsed+=$UnUsed.InputObject;$FreeSize++}
}

$RangeSize=($NumberEnd-$NumberStart)+1
$TotalUsed = $RangeSize-$FreeSize
$TotalFree = $RangeSize-$TotalUsed

Write-Host «Total free numbers in number range » -nonewline
Write-Host $Serie.Identity -NoNewLine -Foregroundcolor Green
Write-Host «, » -NoNewLine
Write-Host $TotalFree -NoNewLine
Write-Host » of»$RangeSize
Write-Host «This range start with » -NoNewLine
Write-Host $NumberStart -NoNewLine -Foregroundcolor Green
Write-Host » and ends with » -NoNewLine
Write-Host $NumberEnd -Foregroundcolor Green
Write-Host «To list available numbers, press «-NoNewLine
Write-Host «L» -NoNewLine -Foregroundcolor Green
$opt = Read-Host » else press Enter»

if($opt -eq «L»){$ListUnUsed}

Write-Host

$FreeSize=0
$ListUnUsed=$NULL
$UsedNumbers=$NULL
}

[System.Console]::ForegroundColor = [System.ConsoleColor]::Gray

Dette innlegget ble publisert i Uncategorized. Bokmerk permalenken.

Legg igjen en kommentar

Fyll inn i feltene under, eller klikk på et ikon for å logge inn:

WordPress.com-logo

Du kommenterer med bruk av din WordPress.com konto. Logg ut / Endre )

Twitter picture

Du kommenterer med bruk av din Twitter konto. Logg ut / Endre )

Facebookbilde

Du kommenterer med bruk av din Facebook konto. Logg ut / Endre )

Google+ photo

Du kommenterer med bruk av din Google+ konto. Logg ut / Endre )

Kobler til %s