List users in OU not enabled for Lync

get-csaduser -filter {Enabled -ne $True} -OU "ou=orgunit,dc=domain,dc=topleveldomain"| sort SamAccountName |ft SamAccountName, UserPrincipalName

Lists users contained in the specified organizational unit that are not enabled for Lync in a table ordered by username (ascending).

Useful for finding users not listed in Lync Server Control Panel. The reason for this is most likely that the user has an AD primary email address (UserPrincipalName) in a domain that is not Sip enabled.

SNAGHTML295c7788

This can happen if your AD domain is not the same as your sip/e-mail domain. To correct this, you could either change the primary email address in AD(best option) and try again when AD is synced, or you could manually specify a sip address in the correct domain (Enable-CSUser –SipAddress “sip:x@y.tld” …)

Listing enterprise voice enabled users and their assigned numbers

I wanted a list containing all OCS users enabled for enterprise voice, and found the answer at UCSpotting. Being difficult, I also wanted to list the pone numbers assigned as Line URIs. I changed the query from UCSpotting and ended up with this:

SELECT r.UserAtHost, p.PhoneNum FROM RTC.dbo.ResourceDirectory c
INNER JOIN RTC.dbo.Resource r ON c.ResourceId = r.ResourceId
INNER JOIN rtc.dbo.ResourcePhone p ON c.ResourceId = p.ResourceId
WHERE (c.OptionFlags & 128) = 128
ORDER BY r.UserAtHost

which returns all enterprise voice enabled users who has an assigned Line URI. But then I thought, what about users with no Line URI? The list containing phone numbers were shorter than the list of voice enabled users, ergo there had to be some users enabled for voice without an assigned Line URI. Experiments showed that such a user could dial out, so listing these users as well seemed pertinent. Changing the last join to a left join instead did the trick:

SELECT r.UserAtHost, p.PhoneNum FROM RTC.dbo.ResourceDirectory c
INNER JOIN RTC.dbo.Resource r ON c.ResourceId = r.ResourceId
LEFT JOIN rtc.dbo.ResourcePhone p ON c.ResourceId = p.ResourceId
WHERE (c.OptionFlags & 128) = 128
ORDER BY p.PhoneNum