This script could be used to enable users and enterprise voice feature in Microsoft Lync Server 2010. It will help you to generate LineUri and provide a confliction detection mechanism. Also you can assign dial plans and voice policies at the same time. It is recommended to use this script right after deploying a new Lync environment. You need to find another solution or extend this script to support user provisioning.
With Enterprise Voice, Microsoft Lync Server 2010 delivers a stand-alone Voice over Internet Protocol (VoIP) offering to enhance or replace traditional PBX systems. Enterprise Voice users can call colleagues on your organization’s VoIP network or PBX, and they can call traditional phone numbers outside your organization.
Currently, administrators feel difficulties when they try to enable users and enterprise voice right after deploying a new Lync environment. It requires a lot of work to assign phone numbers (LineUri) to each user. So administrators do need a script to mitigate this problem.
This script contains two advanced functions, Export-OSCCsAdUser and Enable-OSCCsUser. You can use this script in following ways:
Method 1:
Method 2:
Here are some code snippets for your references. To get the complete script sample, please click the download button at the beginning of this page.
$outputUser = New-Object System.Management.Automation.PSObject
#Prepare required parameters for enabling users
if ($SipAddressType -eq "EmailAddress") {
$sipAddress = "sip:$($csUser.WindowsEmailAddress)"
} else {
$sipAddress = "sip:$($csUser.UserPrincipalName)"
}
$outputUser | Add-Member -MemberType NoteProperty -Name SamAccountName -Value $csUser.SamAccountName
$outputUser | Add-Member -MemberType NoteProperty -Name RegistrarPool -Value $RegistrarPool
$outputUser | Add-Member -MemberType NoteProperty -Name SipAddress -Value $sipAddress
$outputUser | Add-Member -MemberType NoteProperty -Name EnableEnterpriseVoice -Value $EnableEnterpriseVoice
#Prepare additional user scope policy for output
if ($Policy -ne $null) {
foreach ($policyType in $Policy.Keys.GetEnumerator()) {
$outputUser | Add-Member -MemberType NoteProperty -Name "$($policyType)Policy" -Value $Policy[$policyType]
}
}
$outputUser = New-Object System.Management.Automation.PSObject #Prepare required parameters for enabling usersif ($SipAddressType-eq "EmailAddress") { $sipAddress = "sip:$($csUser.WindowsEmailAddress)" } else { $sipAddress = "sip:$($csUser.UserPrincipalName)" } $outputUser|Add-Member-MemberType NoteProperty -Name SamAccountName -Value $csUser.SamAccountName $outputUser|Add-Member-MemberType NoteProperty -Name RegistrarPool -Value $RegistrarPool$outputUser|Add-Member-MemberType NoteProperty -Name SipAddress -Value $sipAddress$outputUser|Add-Member-MemberType NoteProperty -Name EnableEnterpriseVoice -Value $EnableEnterpriseVoice#Prepare additional user scope policy for outputif ($Policy-ne $null) { foreach ($policyTypein$Policy.Keys.GetEnumerator()) { $outputUser|Add-Member-MemberType NoteProperty -Name "$($policyType)Policy"-Value $Policy[$policyType] } }
Example 01: Displays help about Export-OSCCsAdUser
Command: Get-Help Export-OSCCsAdUser -Full
Screenshot:
Example 02: Exports a list of users in specific organizational unit who are not enabled for Lync Server. Meanwhile, assigns a Registrar pool where the user's Lync Server account will be homed.
Command:
Export-OSCCsAdUser -CsvFilePath "c:\Scripts\044\csusers.csv" -OU "ou=users,ou=corp,dc=corp,dc=contoso,dc=com" -RegistrarPool"stdsvr01.corp.contoso.com" –Verbose
Enable-OSCCsUser -CsvFilePath c:\Scripts\044\csusers.csv -Verbose
Screenshot:
Example 03: Exports a list of users in specific organizational unit who are not enabled for Lync Server. Meanwhile, assigns a Registrar pool where the user's Lync Server account will be homed. Then assign specific user scope policy to these
users.
Command:
Export-OSCCsAdUser -CsvFilePath "c:\Scripts\044\csusers.csv" -OU "ou=users,ou=corp,dc=corp,dc=contoso,dc=com" -RegistrarPool "stdsvr01.corp.contoso.com" -Policy @{"Conferencing"="Large Size Meeting"; "Client"="Client Policy 01"}
–Verbose
Enable-OSCCsUser -CsvFilePath c:\Scripts\044\csusers.csv -Verbose
Screenshot:
Example 04: Exports a list of users in specific organizational unit who are not enabled for Lync Server. Meanwhile, assigns a Registrar pool where the user's Lync Server account will be homed. Then the Enterprise Voice feature will
be enabled for these users. A random LineUri will be selected from tel:+17045431000 to tel:+17045431999.
Command:
Export-OSCCsAdUser -CsvFilePath "c:\Scripts\044\csusers.csv" -OU "ou=users,ou=corp,dc=corp,dc=contoso,dc=com" -RegistrarPool "stdsvr01.corp.contoso.com" -EnableEnterpriseVoice -LineUriPrefix "tel:+1704543"
-NumberRangeStart 1000 -NumberRangeEnd 1999 -GenerateRandomPhoneNumber –Verbose
Enable-OSCCsUser -CsvFilePath c:\Scripts\044\csusers.csv -Verbose
Screenshot:
Note: If you plan to use extension number here, the value of LineUriPrefix should be tel:+17045431111;ext=.
Example 05: Exports a list of users in specific organizational unit who are not enabled for Lync Server. Meanwhile, assigns a Registrar pool where the user's Lync Server account will be homed. Then the Enterprise Voice feature will be enabled
for these users. A random LineUri number will be selected from tel:+17045431000 to tel:+17045431999. You can also assign specific dial plan and voice policy to these users.
Command:
Export-OSCCsAdUser -CsvFilePath "c:\Scripts\044\csusers.csv" -OU "ou=users,ou=corp,dc=corp,dc=contoso,dc=com" -RegistrarPool "stdsvr01.corp.contoso.com" -Policy @{"DialPlan"="Dial Plan 01";"Voice"="Purchasing Users"} -EnableEnterpriseVoice -LineUriPrefix "tel:+1704543"
-NumberRangeStart 1000 -NumberRangeEnd 1999 -GenerateRandomPhoneNumber -Verbose
Enable-OSCCsUser -CsvFilePath c:\Scripts\044\csusers.csv -Verbose
Screenshot:
Example 06: Exports a list of users in specific organizational unit who are not enabled for Lync Server. Meanwhile, assign a Registrar pool where the user's Lync Server account will be homed. Then
the Enterprise Voice feature will be enabled for these users. A random LineUri number will be selected in sequence from tel:+17045431000 to tel:+17045431010. If any LineUri confliction is detected, this function will retry 3 times
(default is 5). In worst case, this function will ask you to assign LineUri manually in the .csv file. You can also assign specific dial plan and voice policy to these users.
Command:
Export-OSCCsAdUser -CsvFilePath "c:\Scripts\044\csusers.csv" -OU "ou=users,ou=corp,dc=corp,dc=contoso,dc=com" -RegistrarPool "stdsvr01.corp.contoso.com" -Policy @{"DialPlan"="Dial Plan 01";"Voice"="Purchasing Users"} -EnableEnterpriseVoice -LineUriPrefix
"tel:+1704543" -NumberRangeStart 1000 -NumberRangeEnd 1010 -RetryAttempt 3 -Verbose
Enable-OSCCsUser -CsvFilePath c:\Scripts\044\csusers.csv -Verbose
Screenshot:

Note: It’s possible that the script cannot find an available LineUri for specific users. You need to open the .csv file and assign an available LineUri for these users manually. If you don’t do that, an error will occur.
Technical Resources:
Windows PowerShell Advanced Function
Get-CsAdUser
Forum Threads:
http://social.technet.microsoft.com/Forums/en-AU/ocsvoice/thread/731f1868-45fa-4cbb-adfd-acbdd9f4cf56
http://social.technet.microsoft.com/Forums/da-DK/ocsmanagement/thread/c08fd8b3-f6e4-49b3-a1d6-a3071f3a24db