?
Solved

Get computer properties from Active Directory

Posted on 2010-11-19
7
Medium Priority
?
1,377 Views
Last Modified: 2012-05-10
I am new to Active Directory programming and need some help. I am writing a program that connects to AD and adds all computers to a listbox.

Now I need to now how to get the selected computers information from AD. Specifically I am looking to retrieve the information in the Operating System tab of the properties (i.e. OS Name, Version and Service Pack.)


Any samples and help would be appreciated.
0
Comment
Question by:T-Cornett
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
  • 2
  • +1
7 Comments
 
LVL 74

Assisted Solution

by:Glen Knight
Glen Knight earned 200 total points
ID: 34174979
Active Directory doesn't held this information.

You could use DSQuery to get a list of computers from AD but you would then need to do a WMI call on each individual computer to get this information from the computer itself.

The best way would be to run a collector on the client that sends this information to a central database.
0
 
LVL 27

Assisted Solution

by:KenMcF
KenMcF earned 200 total points
ID: 34175002
You will need to pull these attributes from AD.

operatingSystem
operatingSystemVersion
operatingSystemServicePack
0
 
LVL 5

Assisted Solution

by:CAGdorf
CAGdorf earned 200 total points
ID: 34175004
You can use remote scanning tools as well. We use Spiceworks its free and lets you report off that information as well.
0
Are your AD admin tools letting you down?

Managing Active Directory can get complicated.  Often, the native tools for managing AD are just not up to the task.  The largest Active Directory installations in the world have relied on one tool to manage their day-to-day administration tasks: Hyena. Start your trial today.

 
LVL 74

Expert Comment

by:Glen Knight
ID: 34175088
I stand corrected, thanks KenMcF.

However, I stand by the rest of my post ;)
0
 
LVL 27

Expert Comment

by:KenMcF
ID: 34175130
demazter, I agree with WMI, i think it would give you more accurate information. In AD the data could be stale and computers may not be active anymore. It all depends on the size of the AD env and the cleanup process.
0
 

Accepted Solution

by:
T-Cornett earned 0 total points
ID: 34175681
Thanks for the information. I know WMI will work but since I am trying to learn AD programming I needed an AD solution.

I figured it out though. Here are the two functions I pieced together from code I found online get the OS information. Most of the code I found was for getting user properties but I managed to get it to work for computer properties.

Thanks


Public Function GetComputerOS(ByVal sPC As String, ByVal sDomain As String) As String

        Dim adEntry As New System.DirectoryServices.DirectoryEntry("LDAP://" & sDomain)
        Dim adSearcher As New System.DirectoryServices.DirectorySearcher(adEntry)
        Dim adSearcherResult As System.DirectoryServices.SearchResult
        Dim adResultEntry As System.DirectoryServices.DirectoryEntry

        adSearcher.Filter = "(&(objectClass=computer) (cn=" + sPC + "))"

        Try

            adSearcherResult = adSearcher.FindOne

            adResultEntry = adSearcherResult.GetDirectoryEntry()

            GetComputerOS = getProperty(adResultEntry, "operatingSystem", "Not Found")

        Catch e As Exception
            MsgBox(e.ToString)
            GetComputerOS = "Not Found"
        End Try

    End Function

Private Function getProperty(ByVal adEntry As DirectoryEntry, ByVal sProperty As String, ByVal sReturnFailed As String) As String

        Try
            If adEntry.Properties(sProperty).Value.ToString().Trim() = "" Then
                Return sReturnFailed
            Else
                Return adEntry.Properties(sProperty).Value.ToString()
            End If

        Catch
            Return sReturnFailed
        End Try

    End Function

Open in new window

0
 

Author Closing Comment

by:T-Cornett
ID: 34203735
I am awarding each of you 50 points for trying to help me.
0

Featured Post

Is Your AD Toolbox Looking More Like a Toybox?

Managing Active Directory can get complicated.  Often, the native tools for managing AD are just not up to the task.  The largest Active Directory installations in the world have relied on one tool to manage their day-to-day administration tasks: Hyena. Start your trial today.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Active Directory security has been a hot topic of late, and for good reason. With 90% of the world’s organization using this system to manage access to all parts of their IT infrastructure, knowing how to protect against threats and keep vulnerabil…
Active Directory can easily get cluttered with unused service, user and computer accounts. In this article, I will show you the way I like to implement ADCleanup..
This tutorial will walk an individual through the process of transferring the five major, necessary Active Directory Roles, commonly referred to as the FSMO roles to another domain controller. Log onto the new domain controller with a user account t…
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…
Suggested Courses

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question