Skype for Business – Import Common Area Phones from CSV

I recently had a customer that required 90 Common Area Phones creating in Skype for Business.  This is quite a tedious task so the easiest way is to populate a CSV and use a PowerShell script to do the import.

When creating a Common Area Phone in Lync/SfB it can take a few seconds before you’re able to assign Policies and Pin numbers to the objects.  This slows the script down significantly if waiting 20 seconds between creating the object, then assigning Policies.  So, I’ve actually made three ForEach loops, the first one creates the Common Area Phone objects, then it waits 20 seconds before assigning policies to every object, then it waits another 20 seconds before assigning the pins (I found that assigning Pins would fail if I didn’t wait longer).

Tip – To generate 90 pin numbers I used https://www.randomcodegenerator.com/en/generate-codes.  Set Characters to “Digits” and Output Result to “Txt File”.  You can then copy and paste into your CSV in Excel.

Here is an example CSV file (CommonAreaPhones.csv):

DisplayName,LineURI,Description,DisplayNumber,ConferencingPolicy,PinPolicy,VoicePolicy,DialPlan,Pin
Test Phone1,tel:+44123456789,Test Phone1,+44123456789,Conf-CommonAreaHotDesk,Pin-CommonAreaHotDesk,UK National,SITEA,123987
Test Phone2,tel:+44123456780,Test Phone2,+44123456780,Conf-CommonAreaHotDesk,Pin-CommonAreaHotDesk,UK National,SITEB,123989

Here is the PowerShell script:

Note – If the script fails assigning policies / pins due to not pausing long enough, you can hash out the “New-CsCommonAreaPhone” line and re-run the script to re-assign the policies and pins.  You can also use this method if you need to change any policies.

<#
Author:  Chris Hayward, chrishayward.co.uk
Purpose: Script to bulk import Common Area Phones from CSV
Version: 1.0
Changes: DATE - Change
#>


$filepath = "C:\temp\CommonAreaPhones.csv"          #Specify path to CSV file
$pool = "FEPOOL01.mydomain.local"                   #Specify Lync/Skype for Business Pool
$ou = "ou=Common Area Phones,dc=mydomain,dc=local"  #Specify OU

CLS


# First of all, lets create all of the Common Area Phone objects.......
Import-CSV $filepath | Foreach-Object{
    
    New-CsCommonAreaPhone -LineUri $_.LineURI -RegistrarPool $pool -OU $ou -Description $_.Description -DisplayName $_.DisplayName -DisplayNumber $_.DisplayNumber

}

    # Next we wait 20 seconds before assigning policies
    Write-Output "Waiting 20 seconds"
    Start-Sleep -s 20

# Now lets assign policies to each Common Area Phone
Import-CSV $filepath | Foreach-Object{

    Grant-CsConferencingPolicy -PolicyName $_.ConferencingPolicy -Identity $_.DisplayName
    Grant-CsPINPolicy -PolicyName $_.PinPolicy -Identity $_.DisplayName
    Grant-CsVoicePolicy -PolicyName $_.VoicePolicy -Identity $_.DisplayName
    Grant-CsDialPlan -PolicyName $_.DialPlan -Identity $_.DisplayName

}

    # Wait another 20 seconds for AD/Skype to catch up otherwise setting pin may fail
    Write-Output "Waiting 20 seconds"
    Start-Sleep -s 20

# Finally, set the pin numbers
Import-CSV $filepath | Foreach-Object{   
    Set-CsClientPin –Identity $_.DisplayName -Pin $_.Pin
}

 

3 Replies to “Skype for Business – Import Common Area Phones from CSV”

  1. Pingback: Skype for Business – Import Common Area Phones from CSV | ChrisHayward.co.uk – JC's Blog-O-Gibberish

  2. Pingback: Monthly IT Newsletter – January 2017 – Guy UC World

  3. Pingback: Cheat sheet - Skype for Business | ErwinBierens.com

Leave a Reply

Your email address will not be published. Required fields are marked *

*

This site uses Akismet to reduce spam. Learn how your comment data is processed.