Accessing AD ObjectCategory=Computer

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Fritjolf

    Accessing AD ObjectCategory=Computer

    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,D C=local");
    DirectorySearch er mySearcher = new DirectorySearch er(myDirEntry);
    mySearcher.Filt er =
    string.Format(" (&(objectCatego ry=computer))") ;
    foreach (SearchResult myResult in mySearcher.Find All())
    {

    lbxGetComputers DirSearcher.Ite ms.Add((string) myResult.Proper ties["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.It ems.Add(propert yName);
    }

    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

  • Willy Denoyette [MVP]

    #2
    Re: Accessing AD ObjectCategory= Computer


    "Fritjolf" <Morten.Jacobse n@edb.comwrote in message
    news:1159186784 .058804.222180@ i3g2000cwc.goog legroups.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,D C=local");
    | DirectorySearch er mySearcher = new DirectorySearch er(myDirEntry);
    | mySearcher.Filt er =
    | string.Format(" (&(objectCatego ry=computer))") ;
    | foreach (SearchResult myResult in mySearcher.Find All())
    | {
    |
    |
    lbxGetComputers DirSearcher.Ite ms.Add((string) myResult.Proper ties["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.It ems.Add(propert yName);
    | }
    |
    | 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(SearchR esult myResult in res) {
    foreach( string propName in myResult.Proper ties.PropertyNa mes)
    {
    lbxGetComputers DirSearcher.Ite ms.Add(propName );
    ....

    Willy.





    Comment

    • Fritjolf

      #3
      Re: Accessing AD ObjectCategory= Computer

      Thanx!
      I did try:
      foreach( string propName in
      myResult.Proper ties.PropertyNa mes.ToString())
      but that gave me a compile error.

      Thanx!!!

      foreach(SearchR esult myResult in res) {
      foreach( string propName in myResult.Proper ties.PropertyNa mes)
      {
      lbxGetComputers DirSearcher.Ite ms.Add(propName );
      ...
      >
      Willy.

      Comment

      Working...