none
Need to help to Getting "Linked Master Account" value from Linked mailboxes programmatically by using C# EWS Managed API RRS feed

  • Question

  • Hi all

    I need to get  "Linked Master Account" value  as figure below.


    I try  programming for getting user information from linked mailbox. The code below  I follow  “.\Exchange 2013 101 Code Samples\Exchange 2013 Get user information programmatically”    This sample may be the same method as The article:Using Autodiscover to get user settings .   This sample is pretty easy to understand for a novice exchange developer.   

    Mainly I highly need to get Linked Master Account value of each user in exchange server  in order to use it to proceed subsequent task in my C# coding. Unfortunately,  The  "Linked Master Account"  value was not returned from  this  code below  as expected.   The code show you below.

    using System;
    using System.Text;
    using Microsoft.Exchange.WebServices.Autodiscover;
    using System.Net;
    using System.Collections.Generic;
    namespace Exchange101
    {
        // This sample is for demonstration purposes only. Before you run this sample, make sure that the code meets the coding requirements of your organization.
        class ExChangeGetUserInfo
        {
            static void Main(string[] args)
            {
                Console.Title = "EWS Test Console";
    
                AutodiscoverService autodiscover = new AutodiscoverService();
    
                string username_access="administrator";
                string password_access="**********";
                string domain_access="contoso";
    
    
                autodiscover.Credentials = new NetworkCredential(username_access,password_access ,domain_access);
    
                UserSettingName[] allSettings = (UserSettingName[])Enum.GetValues(typeof(UserSettingName));
    
    
                List<string> listEmail = new List<string>() { "john@contoso.com", "peter@contoso.com", "mice@contoso.com" };
    
                     Console.WriteLine("allSetting Email:" + allSettings.Length);
                foreach (string email in listEmail)
    	{
    
                    Console.WriteLine(string.Format("Email: {0} ",email));
    		 GetUserSettingsResponse response = GetUserSettings(autodiscover,email, 10, allSettings);
           
                int count = 0;
                foreach (UserSettingName settingKey in response.Settings.Keys)
                {
                    count = count + 1;
                    Console.WriteLine(string.Format("{0} - {1}: {2}",count, settingKey, response.Settings[settingKey]));
                }
                 Console.WriteLine(" complete.");
                Console.WriteLine("***************************************************************************************");
    	}
                
                Console.WriteLine("\r\n");
                Console.WriteLine("Press or select Enter...");
                Console.ReadLine();
            }
    
            public static GetUserSettingsResponse GetUserSettings(
                AutodiscoverService service,
                string emailAddress,
                int maxHops,
                params UserSettingName[] settings)
            {
                Uri url = null;
                GetUserSettingsResponse response = null;
    
                for (int attempt = 0; attempt < maxHops; attempt++)
                {
                    service.Url = url;
                    service.EnableScpLookup = (attempt < 2);
    
                    response = service.GetUserSettings(emailAddress, settings);
    
                    if (response.ErrorCode == AutodiscoverErrorCode.RedirectAddress)
                    {
                        url = new Uri(response.RedirectTarget);
                    }
                    else if (response.ErrorCode == AutodiscoverErrorCode.RedirectUrl)
                    {
                        url = new Uri(response.RedirectTarget);
                    }
                    else
                    {
                        return response;
                    }
                }
    
                throw new Exception("No suitable Autodiscover endpoint was found.");
            }
        }
    }

    What is internal name for this attribute???.

    I don’t sure whether or not this sample is achievable to my  requirement.  
    Moreover , are there other ways to get this value ?

    Please advise me
    Thank you for your support.
    Pongthorn



    Wednesday, July 13, 2016 9:54 AM

Answers

All replies

  • You won't be able to get that information using EWS as its a Mailbox Access API and your trying to access directory information so you need to use the Exchange Management shell https://msdn.microsoft.com/en-us/library/office/ff326159(v=exchg.150).aspx and Get-Mailbox which will have that information.

    Otherwise you could use System.DirectoryServices and access Active Directory directly using LDAP.

    Cheers

    Glen

    Thursday, July 14, 2016 1:52 AM
  • You won't be able to get that information using EWS as its a Mailbox Access API and your trying to access directory information so you need to use the Exchange Management shell https://msdn.microsoft.com/en-us/library/office/ff326159(v=exchg.150).aspx and Get-Mailbox which will have that information.

    Otherwise you could use System.DirectoryServices and access Active Directory directly using LDAP.

    Cheers

    Glen

     Finally ,I choose the first option but error was given as below

    I I get certification   as below

    Urgently need help.

    Thank you very much.


    Thursday, July 14, 2016 12:19 PM
  • Certificate based authentication isn't enabled in Exchange by default you can configured it with ActiveSync and OWA with the correct updates https://blogs.technet.microsoft.com/exchange/2012/11/28/configure-certificate-based-authentication-for-exchange-activesync/ but I've never seen anyone use or configure it for the Exchange Management Shell so I wouldn't recommend using it without consulting Microsoft support to get advice on it support/use as if you try to change settings to enable it this may break other components on Exchange and have other unwanted side affects.

    Cheers
    Glen

    Monday, July 18, 2016 2:36 AM
  • Certificate based authentication isn't enabled in Exchange by default you can configured it with ActiveSync and OWA with the correct updates https://blogs.technet.microsoft.com/exchange/2012/11/28/configure-certificate-based-authentication-for-exchange-activesync/ but I've never seen anyone use or configure it for the Exchange Management Shell so I wouldn't recommend using it without consulting Microsoft support to get advice on it support/use as if you try to change settings to enable it this may break other components on Exchange and have other unwanted side affects.

    Cheers
    Glen

     I think that this way is improper for my prpblem   due to the fact that it may  hide unwanted side affects and my customer is pretty concerned if need to have advance configuration as above , 

    therefore  I need to switch to the second way as the first your earlier suggestion   

    "Otherwise you could use System.DirectoryServices and access Active Directory directly using LDAP"

    What attribute in AD schema for getting "Linked Master Account" value?


    Tuesday, July 19, 2016 4:30 AM
  • Do you really need to use certification based authentication ? every commercial product I've ever seen uses Kerberos or Basic Auth to access the Exchange Management Shell.

    >> What attribute in AD schema for getting "Linked Master Account" value?

    You can work that out yourself by using ADSIEdit and you'll also learn something from the process.

    Cheers
    Glen

    Tuesday, July 19, 2016 4:48 AM