C#C
C#2y ago
Wolfman

Unhandled Exception: System.Runtime.InteropServices.COMException:Unknown error (0x8007203b)

I am currently working on a console app that goes through active directory and exports all the computer object to a csv document. This is what I have so far however I keep getting the error noted above when I hit around 3 million computers. Any help would be great!

using System;
using System.DirectoryServices;
using System.IO;

class Program
{
    static void Main()
    {
        string ldapPath = "";
        string csvFile = "AD_Computers.csv";

        using (StreamWriter writer = new StreamWriter(csvFile))
        {
            writer.WriteLine("Name,SerialNumber");

            using (DirectoryEntry entry = new DirectoryEntry(ldapPath))
            {
                using (DirectorySearcher searcher = new DirectorySearcher(entry))
                {
                    searcher.ServerTimeLimit = new TimeSpan(1,0,0);
                    searcher.Filter = "(objectCategory=computer)";
                    searcher.PropertiesToLoad.Add("name");
                    searcher.PropertiesToLoad.Add("serialNumber");

                    foreach (SearchResult result in searcher.FindAll())
                    {
                        string name = result.Properties["name"][0].ToString();
                        string serialNumber = result.Properties.Contains("serialNumber") ? result.Properties["serialNumber"][0].ToString() : "";

                        writer.WriteLine($"{name},{serialNumber}");
                    }
                }
            }
        }

        Console.WriteLine($"AD computers exported to {csvFile}");
    }
}
Was this page helpful?