I'm trying to retrieve the following information from a Azure AD managed user account

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.DirectoryServices.AccountManagement;

namespace UserName_API_functionCall
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine("User Principal parameter values");
            UserPrincipal current = UserPrincipal.Current;
            Console.WriteLine("User email: {0}", current.EmailAddress);
            Console.WriteLine("User email: {0}", current.MiddleName);
            Console.WriteLine("User email: {0}", current.GivenName);
            Console.WriteLine("User email: {0}", current.Surname);
            Console.ReadLine();
        }
    }
}

However the UserPrincipal.Current method call fails with an exception, as it (when the user is Azure AD connected) returns a GroupPrincipal data type rather than a UserPrincipal data type (with no cast ability)

How do I then most effectively retrieve the "current user" information from local populated properties?

Thanks

0

There are 0 answers