Search code examples
tfsidentity-management

How to retrieve user email from username in PowerShell for TFS?


I am using TFS IIdentityManagementService2 in powershell to get User details of a user object (Assigned To / Created By field). I am able to get User Unique name like Domain\username. How do I get email id of the user now?


Solution

  • You could use the GetProperty method on your TeamFoundationIdentity object with the "Mail" key:

    user.GetProperty("Mail")
    

    A sample code for your reference:

    private static readonly Func<TeamFoundationIdentity, string> _emailSelector =
                identity =>
                {
                    object value;
                    if (identity.TryGetProperty("ConfirmedNotificationAddress", out value) && !string.IsNullOrWhiteSpace((string)value))
                    {
                        return (string) value;
                    }
    
                    return (string) identity.GetProperty("Mail");
                };
    

    You could also take a look at below related articles: