By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
434,894 Members | 1,942 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 434,894 IT Pros & Developers. It's quick & easy.

Accessing AD ObjectCategory=Computer

P: n/a
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)myRes ult.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

Sep 25 '06 #1
Share this Question
Share on Google+
2 Replies


P: n/a

"Fritjolf" <Mo*************@edb.comwrote in message
news:11**********************@i3g2000cwc.googlegro ups.com...
| 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)myRes ult.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.

Sep 25 '06 #2

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

Thanx!!!

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

Willy.
Sep 26 '06 #3

This discussion thread is closed

Replies have been disabled for this discussion.