Avatar of Lazaro Rondon
Lazaro Rondon

asked on 

Getting direct reports under another manager's direct reports list

I've been trying to figure out how to do this but I'm always met with a bump on the road. What I'm trying to do is to get the reporting people under my manager's direct reports list; so for example, "Alex" is a direct report under my manager, however, when you go into his organization you see that he also has direct reports that report directly to him - I am trying to get "those" reports not only from his side but from anyone else in the list that has direct reports as well. What is needed for me to effectively execute that idea? Many thanks!

This is my code to only get Direct Reports under my manager tree:
    public void GetManagerDirectReports()
        {
            Application App = new Application();
            AddressEntry currentUser = App.Session.CurrentUser.AddressEntry;
            if (currentUser.Type == "EX")
            {
                ExchangeUser manager = currentUser.GetExchangeUser().GetExchangeUserManager();
                if (manager != null)
                {
                    AddressEntries addrEntries = manager.GetDirectReports();
                    if (addrEntries != null)
                    {
                        foreach (AddressEntry addrEntry in addrEntries)
                        {
                            ExchangeUser exchUser = addrEntry.GetExchangeUser();
                            StringBuilder sb = new StringBuilder();
                            sb.AppendLine("Name: "
                                + exchUser.Name);
                            sb.AppendLine("Title: "
                                + exchUser.JobTitle);
                            sb.AppendLine("Department: "
                                + exchUser.Department);
                            sb.AppendLine("Email: "
                                + exchUser.PrimarySmtpAddress);
                            Debug.WriteLine(sb.ToString());
                            Console.WriteLine(sb.ToString());
                            Console.ReadLine();
                        }
                    }
                }
            }
        }

Open in new window

ExchangeOutlookC#Active DirectoryPowershell

Avatar of undefined
Last Comment
AndyAinscow

8/22/2022 - Mon