Since you are using CodedUI for this I would write something like this.

    public static void GetAllElements(BrowserWindow bw)
    {
    var a = bw.GetChildren().Where(x => x.GetProperty("TagName").ToString() == "TD");
                foreach (var control in a)
                {
                    Console.WriteLine(control.Name);
                    Console.WriteLine(control.GetProperty("Id"));
                }
    }