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



Test Jabra Engage 75 [**UPDATE**]

From Tektracom I got the new Jabra Engage 75 MONO today as I wanted to test it out. Jabra Engage 75  As we can see we have a docking t...