Determining whether a user is enabled for Skype for Business (Lync)

The following code sample determines whether a user is enabled for Skype for Business.

PowerShell
[Reflection.Assembly]::LoadWithPartialName("Softerra.Adaxes.Adsi")

# Connect to the Adaxes service
$ns = New-Object("Softerra.Adaxes.Adsi.AdmNamespace")
$service = $ns.GetServiceDirectly("localhost")

# Bind to the user
$userDN = "CN=John Smith,CN=Users,DC=domain,DC=com"
$user = $service.OpenObject("Adaxes://$userDN", $null, $null, 0)

# Is enabled for Skype for Business?
$enabledForLync = $user.IsLyncEnabled
C#
using Softerra.Adaxes.Interop.Adsi;
using Softerra.Adaxes.Adsi;
class Program
{
    static void Main(string[] args)
    {
        // Connect to the Adaxes service
        AdmNamespace ns = new AdmNamespace();
        IAdmService service = ns.GetServiceDirectly("localhost");

        // Bind to the user
        const string userPath = "Adaxes://CN=John Smith,CN=Users,DC=domain,DC=com";
        IADs user = (IADs)service.OpenObject(userPath, null, null, 0);

        // Is enabled for Skype for Business?
        lyncOps = (IAdmLyncOps)user;
        bool enabledForLync = lyncOps.IsLyncEnabled;
    }
}

See also