Lync enable members of a group

For this task I needed to Lync enable all members of an [nested] AD group.  Following is a script I created (with lots of help).  It will prompt for the group name and report on:

  • # of users already Lync enabled
  • # of users that do not have a mailbox
  • # of users that were Lync enabled
Import-Module activedirectory -ErrorAction "SilentlyContinue"
Import-Module lync -ErrorAction "SilentlyContinue"
Write-Host
Write-Host "This script will Lync enable all members of nested AD group that have a mailbox"
Write-Host
Write-Host "Enter DN, SID, GUID, or Domain\Name
of the group to be enabled for Lync:" -ForegroundColor White
$GroupName = read-host
$EnabledCount = 0
$NoMailboxCount = 0
$AlreadyLyncEnabledCount = 0

$InGroupCount = 0
$MovedCount = 0

#Gather all of the group members into $GroupMembers
$GroupMembers = Get-ADGroupMember -Recursive $GroupName | Sort-Object Name

foreach ($Member in $GroupMembers){
	$CSADUserInfo = Get-CsAdUser -identity $Member.distinguishedname

	#Check if they are already Lync enabled
	if ($CSADUserInfo.enabled -eq $null){

		#Check if they have a mailbox then Lync enable them or skip if they dont.
		if ((Get-User $CSADUserInfo.distinguishedname).RecipientTypeDetails -eq "UserMailbox"){
			Enable-CSuser -identity $ADUserInfo.distinguishedname -RegistrarPool poolname.domain.com -SipAddressType EmailAddress
			write-host $CSADUserInfo.name " is now Lync enabled" -ForegroundColor Green
			$EnabledCount++
		}else{
			write-host $CSADUserInfo.name " does not have a mailbox" -ForegroundColor Red
			$NoMailboxCount++
			}
	}else{
		$AlreadyLyncEnabledCount++
		#write-host	$CSADUserInfo.name " is already Lync enabled."  -ForegroundColor Yellow
		}
  	}

Write-Host
Write-Host ($GroupMembers | measure).count ": total members in group" -ForegroundColor Green
Write-Host $AlreadyLyncEnabledCount ": already enabled" -ForegroundColor Yellow
Write-Host $NoMailboxCount ": do not have a mailbox" -ForegroundColor Red
Write-Host $EnabledCount ": were enabled" -ForegroundColor Green

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s