Script Prerequisites
Create a New Client Policy to Support Hot-Desking
As indicated in the TechNet article, a client policy should be created to enable hot-desking on common area phones. The PowerShell command below performs the following functions:
- Creates a new client policy named KCDEMO-CommonAreaPhoneClientPolicy
- Enables hot-desking
- Defines a hot-desking inactivity value of 30 minutes
Table 1 – Common Area Phone Client Policy
New-CsClientPolicy -Identity KCDEMO-CommonAreaPhoneClientPolicy -EnableHotdesking $True -HotdeskingTimeout 00:30:00 |
Create a New Common Area Phone Voice Policy
As indicated in the TechNet article, a restricted voice policy should also be created for common area phones. The command below performs the following functions:
- Creates a new voice policy named KCDEMO-CommonAreaPhoneClientPolicy
- Assigns PSTN usages of KCDemo-Internal, KCDemo-Local, KCDemo-LD, and KCDemo-International
- Disables Simultaneous Ring
- Disables Call Forwarding
- Disables Delegation
- Disables Team Call
- Disables Call Transfer
Table 2 – Common Area Phone Voice Policy
New-CsVoicePolicy -Identity KCDEMO-CommonAreaPhoneVoicePolicy -PstnUsages @{add=”KCDemo-Internal”, “KCDemo-Local”, “KCDemo-LD”, “KCDemo-International”} -AllowSimulRing $False -AllowCallForwarding $False -Name KCDEMO-CommonAreaPhoneVoicePolicy -EnableDelegation $False -EnableTeamCall $False -EnableCallTransfer $False |
If necessary, additional conferencing and PIN policies could be created at this point. This blog will simply focus on the client and voice policies.
Script Creation
Common Area Phone PowerShell Script
Once the prerequisite policies have been created, it’s time to create the common area phone script. Credit should be given to the Lync PowerShell article for providing the initial structure of the PowerShell script below and to Jason Shave’s blog for providing background on assigning common area phone SipAddresses and dial plans.
The script below will perform the following functions:
- Prompt for a CSV file to import
- Create an output text file in the same directory as the PowerShell script
- Import the contents of the CSV file
- Create a new common area phone account and define the display name, registrar pool, organizational unit location, description, line URI, display number, and SipAddress
- Assign the KCDEMO-CommonAreaPhoneClientPolicy client policy to each common area phone account
- Assign the KCDEMO-CommonAreaPhoneVoicePolicy voice policy to each common area phone account
- Assign the KCDEMO-CHI dial plan to each common area phone account
-
Sleep for 60 seconds
- Errr wait⦠Why am I making the script pause for 60 seconds? If the script does not pause, the script will output an error similar to Table 3 below
Table 3 – Error if Script Does Not Pause for ~60 Seconds
Set-CsClientPin : ###50010:UpinSetPin:commonphone5@kcdemo.com is not found in this database. At C:Lync Reference FilesCommon Area PhonesSetPIN.ps1:11 char:86 + Get-CsClientPinInfo -Identity $importedCommonAreaPhone.SipAddress | Set-CsClientPin <<<< -Pin $importedCommonAreaPhone.PIN + CategoryInfo : InvalidOperation: (Microsoft.Rtc.Common.Data.DBCore:DBCore) [Set-CsClientPin], SqlException + FullyQualifiedErrorId : ###50010:UpinSetPin:commonphone5@kcdemo.com is not found in this database.,Microsoft.Rtc.Management.UserPinService.SetOcsUserPinCmdlet |
- After pausing for 60 seconds, the script will retrieve the PIN information and ultimately set the PIN for each common area phone account in the CSV file
The code for the CommonAreaPhones.ps1 PowerShell script is below.
Table 4 – Common Area Phone PowerShell Script
param( [string] $importfile = $(Read-Host -prompt “Please enter a file name”)) $importedCommonAreaPhones = Import-Csv $importfile$transcriptname = “CreateCommonAreaPhones” + (Get-Date -Format s).Replace(“:”,”-“) +”.txt”Start-Transcript $transcriptnameforeach ($importedCommonAreaPhone in $importedCommonAreaPhones) { New-CsCommonAreaPhone -DisplayName $importedCommonAreaPhone.DisplayName -RegistrarPool $importedCommonAreaPhone.RegistrarPool -OU $importedCommonAreaPhone.OU -Description $importedCommonAreaPhone.Description -LineUri $importedCommonAreaPhone.LineURI -DisplayNumber $importedCommonAreaPhone.DisplayNumber -SipAddress $importedCommonAreaPhone.SipAddress -Verbose Grant-CsClientPolicy -Identity $importedCommonAreaPhone.DisplayName -PolicyName $importedCommonAreaPhone.ClientPolicyName Grant-CsVoicePolicy -Identity $importedCommonAreaPhone.DisplayName -PolicyName $importedCommonAreaPhone.VoicePolicyName Grant-CsDialPlan -Identity $importedCommonAreaPhone.DisplayName -PolicyName $importedCommonAreaPhone.DialPlan }sleep 60 foreach ($importedCommonAreaPhone in $importedCommonAreaPhones) { Get-CsClientPinInfo -Identity $importedCommonAreaPhone.SipAddress | Set-CsClientPin -Pin $importedCommonAreaPhone.PIN } Stop-Transcript |
The formatting of the CommonAreaPhones.ps1 script should appear similar to the Figure 1 below.
Figure 1 – CommonAreaPhones.ps1 Screenshot
Common Area Phone CSV File
For the script to perform its function, important pieces of information should to be funneled into the script. To handle this funneling, a CSV file should be created with the appropriate attributes such as:
- DisplayName
- RegistrarPool
- OU
- Description
- LineURI
- DisplayNumber
- SipAddress
- PIN
- VoicePolicyName
- ClientPolicyName
- DialPlan
The contents of the common area phone CSV file should appear similar to Table 5 below. The PowerShell script contains variables that match each column of the CSV file. For example, to import the display name the PowerShell script uses $importedCommonAreaPhone.DisplayName and looks for DisplayName as the column header.
Table 5 – Common Area Phone CVS Import File
DisplayName,RegistrarPool,OU,Description,LineURI,DisplayNumber,SipAddress,PIN,VoicePolicyName,ClientPolicyName,DialPlan “Common Phone 1″,”vlaplyc200.kcdemo.net”,”OU=Common Area Phones,OU=Misc,DC=KCDEMO,DC=net”,”Common Phone 1″,”tel:+15552221111″,”+1 (555) 222-1111″,”sip:commonphone1@kcdemo.com”,21701,KCDEMO-CommonAreaPhoneVoicePolicy,KCDEMO-CommonAreaPhoneClientPolicy,”KCDEMO-CHI” “Common Phone 2″,”vlaplyc200.kcdemo.net”,”OU=Common Area Phones,OU=Misc,DC=KCDEMO,DC=net”,”Common Phone 2″,”tel:+15552221112″,”+1 (555) 222-1112″,”sip:commonphone2@kcdemo.com”,21701,KCDEMO-CommonAreaPhoneVoicePolicy,KCDEMO-CommonAreaPhoneClientPolicy,”KCDEMO-CHI” “Common Phone 3″,”vlaplyc200.kcdemo.net”,”OU=Common Area Phones,OU=Misc,DC=KCDEMO,DC=net”,”Common Phone 3″,”tel:+15552221113″,”+1 (555) 222-1113″,”sip:commonphone3@kcdemo.com”,21701,KCDEMO-CommonAreaPhoneVoicePolicy,KCDEMO-CommonAreaPhoneClientPolicy,”KCDEMO-CHI” “Common Phone 4″,”vlaplyc200.kcdemo.net”,”OU=Common Area Phones,OU=Misc,DC=KCDEMO,DC=net”,”Common Phone 4″,”tel:+15552221114″,”+1 (555) 222-1114″,”sip:commonphone4@kcdemo.com”,21701,KCDEMO-CommonAreaPhoneVoicePolicy,KCDEMO-CommonAreaPhoneClientPolicy,”KCDEMO-CHI” “Common Phone 5″,”vlaplyc200.kcdemo.net”,”OU=Common Area Phones,OU=Misc,DC=KCDEMO,DC=net”,”Common Phone 5″,”tel:+15552221115″,”+1 (555) 222-1115″,”sip:commonphone5@kcdemo.com”,21701,KCDEMO-CommonAreaPhoneVoicePolicy,KCDEMO-CommonAreaPhoneClientPolicy,”KCDEMO-CHI” |
Once the CSV file is created, the final formatting should appear similar to Figure 2 below.
Figure 2 – CommonAreaPhones.csv Screenshot
Script Execution
To execute the script, perform the actions below.
- Launch the Lync Management Shell as an administrator
- Change directories to the script location and execute the script (.CommonAreaPhones.ps1)
- Input the name of the CSV file (CommonAreaPhones.csv)
Figure 3 – Script Execution
Once the script execution completes, the PowerShell output should appear similar to Figure 4 below.
Figure 4 – PowerShell Output
The transcript file will be created in same location as the PowerShell script. The output should be similar to Figure 5 below.
Figure 5 – Transcript
Finally, the common area phone contact objects should appear in the OU that was specified in the CSV file.
Figure 6 – Contact Objects
To avoid any space issues with copying/pasting of the code above (or em-dashes β thanks Andy Olson), the script and CSV file can be downloaded here: Common Area Phone Bulk Creation Script.
Comments welcomed!
Pingback: β¦ and I thought I saw a 2: MAdCaP.ps1 β A GUI for Lync Analog Devices & Common Area Phones « Lync News
I’ll test this out. But one comment – left justify all code blocks, and put them in monospace fonts like Courier New. It makes them easier to read.
Hey Pat, I totally agree with you. Long story short, a few of my old blogs were migrated over from an older system and there were a few formatting issues. Thanks for the feedback.
Keenan
Keenan, thanks for this great guide! We decided on the fly to set up our new Polycoms as hotdesking phones. Thanks to this I had everything set (and working on the first try!) within a few short minutes.
Hey Joe, thanks for the feedback. I’m glad the script helped!
Pingback: … and I thought I saw a 2 » Blog Archive » MAdCaP.ps1 – A GUI for Lync Analog Devices & Common Area Phones
The link for downloading the scripts and the CSV file is no longer available.
Thanks for your script that save us time π
Thanks for this, saved me a job! Quick and easy to follow. Thanks for sharing π
Thanks for the note Sebastien. We migrated our blogs from another platform and it looks like my attachments weren’t carried over. I’ll get this fixed. Happy holidays!