Powershell: Enable multiple Lync 2013 users

When you have a large Lync 2013 environment with several OU’s, you want to “Lync enable” users automatically, and maybe you require a specific user policy for those users. (As you can see i used a VDI policy in my example) With this powershell script you can add as many OU’s as you like as long as you separate them with a comma. Users to enable within a specific OU are selected by: AD account is not disabled, AD account has an e-mail address, AD account is not Lync enabled yet. When you fill out the configuration lines at the begin, your ready to go. You have to run the script on a machine with the Lync cmdlets (Administrative Tools). I’ve tested the script for Lync 2013 implementations.

#
# Enable Lync users in a specific OU with logging
# (c)2014 Hendricus Kramer - PepperByte
#
$LOGLOC = "c:\lync"
$LYNCPOOLFQDN = "lyncpool.peppercrew.nl"
# When you have more then one OU, you can separate them with a comma.
$ACTIVATEOU = "OU=User,OU=Accounts,DC=peppercrew,DC=nl","OU=Lync,OU=Accounts,DC=peppercrew,DC=nl"
# Client policy empty for default or for VDI (!!create VDI policy first!!)
$CLIENTPOLICY = "VDI"
#
############ (-:-) DO NOT EDIT BELOW THIS LINE (-:-) ############
#
clear
$TITLE = "Lync 2013 enable users script"
$VERSION = "0.1"
$AUTHOR = "Hendricus Kramer - PepperByte @ www.pepperbyte.com"
$FILEDATE = $(get-date -f dd-MM-yyyy)
$FILETIME = $(get-date -f HH:mm)
$LOGFILE = "$LOGLOC\userenablelog-$FILEDATE.txt"
#
if (Test-Path $LOGLOC) {"Do Nothing" | Out-Null}Else{mkdir $LOGLOC | Out-Null}
#
"[x] starting $TITLE $VERSION by $AUTHOR" | Tee-Object $LOGFILE
#
#
Import-module Lync
$USERENABLE = $null
$USERSFROMOU = $ACTIVATEOU | Foreach {Get-CsAdUser -Filter {Enabled -ne $True} -OU $_ | Where-Object {$_.UserAccountControl -notlike "*AccountDisabled*"} | Where-Object {$_.WindowsEmailAddress -ne ""} | Where-Object {$_.SIPAddress -eq ""} };
#
"   [X] Determine user locations" | Tee-Object $LOGFILE -Append
ForEach ($OU in $ACTIVATEOU){"      [X] location: $OU" | Tee-Object $LOGFILE -Append }
if ($USERSFROMOU -ne $null) {
        if ($CLIENTPOLICY -eq ""){"   [X] Enabled users with default policy"}Else{"   [X] Enabled users with $CLIENTPOLICY clientpolicy" }
        $USERSFROMOU | Foreach-Object {
        $USERENABLE = $null
             Enable-CsUser -Identity $_.UserPrincipalName -RegistrarPool $LYNCPOOLFQDN -SipAddressType EmailAddress
        $USER = $_.Name -split "," -split "="
        "      [U] $USER" | Tee-Object $LOGFILE -Append; if ($CLIENTPOLICY -eq ""){}Else{Grant-CsClientPolicy -Identity $_.UserPrincipalName -PolicyName $CLIENTPOLICY}
       }
     }Else{"   [!] Nothing to do here...." | Tee-Object $LOGFILE -Append; "   [!] If you think think this is an error, you have to check the Active Directory location of the user" | Tee-Object $LOGFILE -Append}
"[X] Script ends here" | Tee-Object $LOGFILE -Append

Was once an enthusiastic PepperByte employee but is now working elsewhere. His blogs are still valuable to us and we hope to you too.