Powershell Script enable users in different OU's and with enterprise Voice

To make Automatic enable users from AD to Lync With Enterprise Voice. I have made a PowerShell script to do this.
This script can be used as a scheduled task.  This can be used as you want it.
Here is the code:

#Script for automatic enable users for Lync 2013

#THere can be used list of OU,DC if users are in different OU's.

#Remember to change RegistrarPool

#SipAddresser is EQ Mailaddress

#Made by Kai Stenberg, Solution Architect Lync Skill AS

#$write shall be set to $true when running the script in production
$write = $false;

#Delete old files if the script has been run before
if (Test-Path c:\temp\disabledLyncUsers.txt) {

del c:\temp\disabledLyncUsers.txt;

if (Test-Path c:\Temp\enabledLyncUsers.txt) {

del c:\Temp\enabledLyncUsers.txt;

#set up your list of OU's and domain name

#See the example under, has to be changed to your settings
$adOus = ("OU=Employees,OU=Users,OU=HQ,DC=domain,DC=local",


#New users will be enabled and Enterprice voice ready
foreach ($ou in $adOus) {

$newLyncUser = get-csaduser -OU $ou -filter { Enabled -ne $true }

foreach ($user in $newLyncUser) {

if ($write) {

$user | Enable-csuser -RegistrarPool <poolname of Lync> -SipAddressType EmailAddress;

$user | Set-CsUser -EnterpriseVoiceEnabled $true;

#If using other Dialplan or voice policy then Global please remove the # on the next 2 rows

#$user | Set-CsUser -Dialplan "<name of dialplan>"

#$user | Set-CsUser -VoicePolicy "<name of Voicepolicy>"

else {

$user | Out-File -Append c:\Temp\disabledLyncUsers.txt;




# get-csaduser -filter {Enabled -ne $True -and OU -iin $adOus} | foreach {

# Enable-CsUser -RegistrarPool <poolnameFQDN> -SipAddressType EmailAddress}

# Set-CsUser -EnterpriseVoiceEnabled $true

#LineURI with +47 is to be set for Lync Telephony
$enabledUsers = Get-CsAdUser -Filter {Enabled -ne $Null}

foreach ($user in $enabledUsers) {

if ($write) {

$phoneNumber = "TEL:" + "+47" + ($user.$phone -replace "[^0-9]","")

# $phoneNumber = $phoneNumber -replace "[^0-9]"

# $phonenumber = "TEL:+" + $phoneNumber

$user | Set-CsUser -LineUri $phoneNumber


else {

$user | Out-File -Append c:\Temp\lyncEnabledUsers.txt




  1. Can it be used to enable users in LYNC 2010 pool?

  2. I can't see that this should not be any problem. Try it With $Write=false$ parameter and then you will see the result. :-) Good luck

  3. is there anyway to get this to fully provision the account from AD user object ie tel : number and policy ect.

    Identity : CN=firstname lastname,OU=Users,OU=Thailand-Bangkok,DC=contoso,DC=com
    VoicePolicy : VP_somthing
    VoiceRoutingPolicy :
    ConferencingPolicy : Policy Conf XXXX
    PresencePolicy :
    DialPlan :
    LocationPolicy :
    ClientPolicy :
    ClientVersionPolicy :
    ArchivingPolicy :
    ExchangeArchivingPolicy : Uninitialized
    PinPolicy :
    ExternalAccessPolicy :
    MobilityPolicy :
    PersistentChatPolicy :
    UserServicesPolicy :
    HostedVoiceMail :
    HostedVoicemailPolicy :
    HostingProvider : SRV:
    RegistrarPool : XX-XX-XX.contoso.com
    Enabled : True
    SipAddress : sip:firstname lastname@contoso.com
    LineURI : tel:+0000000000
    EnterpriseVoiceEnabled : True
    ExUmEnabled : False
    HomeServer : CN=Lc Services,CN=Microsoft,CN=1:1,CN=Pools,CN=RTC Service,CN=Services,CN=Configuration,DC=contoso,DC=com
    DisplayName : firstname lastname
    SamAccountName : firstname lastname

    Any help with this would be soo apreciated!



35 weeks and counting

 Well now its 248 days for the Skype Online shutdown today, are you ready? Well it's time to get ready. During the last week many of you...