20 thoughts on “SCRIPT: List-UnusedNumbers.ps1

    • Hi Alex, thanks for trying my script :)

      It should work and works in my lab. The line number 31 removes everything after ; “$used=$used | ForEach-Object {$_.split(‘;’)[0]}”

      Are you sure you changed all the +47 prefixes?

      • I did change all the +47s but I had to do this – $_.Replace(“tel:+14085551234;ext=”, “”) where +14085551234 was the DID. Pretty simple and I can’t believe it took me that long to figure out :)

        GREAT script BTW!

      • Only the extensions, but I could have changed that the in write-output field to add it back in. I also added a function to write to a log file.

        • Sounds great, I am looking into makin the script more generic regarding countrycode and so forth. All tips are appreciated.

          Other areas I see this script can develop is being even more generic, and be part of a script enabling users for Enterprise Voice.

  1. I found a fix. Where you eliminated “tel:+47″ I changed that to be the full DID and ext part so “+14085551234;ext=” Now it returns all the “open” extensions.

  2. One additional item you should add is the new Private Line feature. With this it should be complete I guess :)

    Get-CsUser -Filter {PrivateLine -ne $Null}

  3. New updates to the script:
    After some great feedback I have updated the script to be much more dynamic by supporting different country codes in the same deployment
    Added check if Unassigned Numbers are in E.164 format, if its not, continue to the next number serie

  4. Great script but it has an issue when using typical 10 digit dialing in the U.S.. The Range Operator code on line 43 ($Ser=$NumberStart..$NumberEnd) is limited to only 32-bit values (-2,147,483,648 and 2,147,483,647). In the instance of 10 digit dialing where the area code begins with say 412 (4125551212), the script will fail with the following error – “Cannot convert value “4125551212” to type “System.Int32″. Error: “Value was either too large or too small for an Int32.”

    Editing the $CountryCodeLength variable to “4” to strip out the area code will work but is really only useful if you only have a single area code in the DID range. I some US cities, you can have multiple area codes (i.e. 412, 325, 514) so if you used this method, you would not know what area code prefix goes with the unassigned number that was listed.

    I’m new to powershell and have been looking for a way to update the script to work. Will probably have to do it with an array of some sort but I’m not that good yet. Would appreciate any assistance.

  5. [...] I created this script in January 2011 during a long weekend and have been using it ever since. It even got published as the only external script at the Lync PowerShell blog, which I am very proud of. You can find the script here: List-UnusedNumbers.ps1. [...]

  6. Brilliant script, only issue I have found is that it doesn’t take in to account numbers used by response groups. Not sure if this can be fixed but other than that it is great!!

    • Hi, thanks for commenting.

      This line should find numbers used by response groups, let me know it that is not the case: $Used+=Get-CsRgsWorkflow | Select-Object LineURI | out-string -stream

      • How odd, if I run the command on its own it brings up the response group numbers without an issue and lists 9. The only reason I know for sure it isn’t working is that we have a number range with 20 numbers dedicated to response groups and it lists all 20 of them as free when 9 are in use.

        Very strange!

        • Yes, strange, its tested ok in other deployments, could you send me the number series configuration offline? So I can have a quick look at it and maybe test it in lab.

          /Ståle

  7. Hi,
    Trying to use your script… couple of questions. Is line 99 the last line?
    also.. when I run it.. all I get is the “script for finding unused numbers in Lync 2010 by Stale hansen” & nothing else.
    Dont suppose you have suggestion/idea of issue? :)

  8. […] will give you the result you are looking for. But a user is not the only object in Lync that can have a LineUri, and if you in addition don’t know what object has the LineUri you might need to search through all the objects. This script does just that. Sort of an opposite to Ståle Hansens List-UnusedNumbers.ps1. […]

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s