Lync count by OU

This script will give you the counts of users that are Lync enabled in a particular OU.  It distinguishes between those accounts with a mailbox as this organization requires an account to have a mailbox before it is enabled for Lync.  Comments or suggestions always welcome!!

  • # Total users in OU
  • # Lync enabled count of users in that OU
  • # Users not Lync enabled and that do have a mailbox.
  • # User without mailbox
Import-Module lync -ErrorAction "SilentlyContinue"
$OUname = "OU=hr,OU=users,DC=contoso,DC=com"
$UserCount = 0
$EnabledCount = 0
$NotEnabledCount = 0
$SkippedCount = 0
$NoMBXCount = 0

#Gather all of the group members into $GroupMembers
$OUMembers = Get-csADuser -OU $OUname

foreach ($Member in $OUMembers){
	$UserCount++
	$CSADUserInfo = Get-CsAdUser -identity $Member.distinguishedname

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

		#Check if they have a mailbox
		if ((Get-User $CSADUserInfo.distinguishedname).RecipientTypeDetails -eq "UserMailbox"){
			$NotEnabledCount++
		}else{
		$NoMBXCount++
			}
	}else{
		$EnabledCount++
		}
  	}

Write-Host
Write-Host ($OUMembers | measure).count ": total members in" $OUname
Write-Host $UserCount ": total users processed"
Write-Host $EnabledCount ": are Lync enabled"
Write-Host $NotEnabledCount ": are not Lync enabled"
Write-host $NoMBXCount ": do not have a mailbox"

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