Accessing AD ObjectCategory=Computer

  • Thread starter Thread starter Fritjolf
  • Start date Start date
F

Fritjolf

Hi.

I've written some code to list objects of type "Computer" from our
firms primary AD controller. The code is simple:

DirectoryEntry myDirEntry = new
DirectoryEntry("LDAP://DC=DomainName,DC=local");
DirectorySearcher mySearcher = new DirectorySearcher(myDirEntry);
mySearcher.Filter =
string.Format("(&(objectCategory=computer))");
foreach (SearchResult myResult in mySearcher.FindAll())
{

lbxGetComputersDirSearcher.Items.Add((string)myResult.Properties["name"][0]);
}

This code lists the computername of 5500 computers (with pagesize and
sizelimit also set in the searcher object).

A object of type computer has (from what I can see) 35 properties.

Here is the (most likely) simple thing I can't manage:
How do I iterate through a Computer object and just write the property
names to a listbox? It should be easy with the use of a foreach loop.
Something like:
foreach (string propertyName in ComputerObject
{
lbxPropNames.Items.Add(propertyName);
}

But I just can't figure out the syntax.
And yes, I am new to C# (although not new to programming)

Help is GREATLY apreciated!!!

Thanx,

Fritjolf
 
| Hi.
|
| I've written some code to list objects of type "Computer" from our
| firms primary AD controller. The code is simple:
|
| DirectoryEntry myDirEntry = new
| DirectoryEntry("LDAP://DC=DomainName,DC=local");
| DirectorySearcher mySearcher = new DirectorySearcher(myDirEntry);
| mySearcher.Filter =
| string.Format("(&(objectCategory=computer))");
| foreach (SearchResult myResult in mySearcher.FindAll())
| {
|
|
lbxGetComputersDirSearcher.Items.Add((string)myResult.Properties["name"][0]);
| }
|
| This code lists the computername of 5500 computers (with pagesize and
| sizelimit also set in the searcher object).
|
| A object of type computer has (from what I can see) 35 properties.
|
| Here is the (most likely) simple thing I can't manage:
| How do I iterate through a Computer object and just write the property
| names to a listbox? It should be easy with the use of a foreach loop.
| Something like:
| foreach (string propertyName in ComputerObject
| {
| lbxPropNames.Items.Add(propertyName);
| }
|
| But I just can't figure out the syntax.
| And yes, I am new to C# (although not new to programming)
|
| Help is GREATLY apreciated!!!
|
| Thanx,
|
| Fritjolf
|

foreach(SearchResult myResult in res) {
foreach( string propName in myResult.Properties.PropertyNames)
{
lbxGetComputersDirSearcher.Items.Add(propName);
....

Willy.
 
Thanx!
I did try:
foreach( string propName in
myResult.Properties.PropertyNames.ToString())
but that gave me a compile error.

Thanx!!!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top