Wolfman
Wolfman
Explore posts from servers
Mmalefashionadvice
Created by Wolfman on 5/31/2024 in #questions-and-advice
Looking for critiques on groom suit
No description
8 replies
CC#
Created by Wolfman on 2/8/2024 in #help
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}");
}
}
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}");
}
}
26 replies