• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1420
  • Last Modified:

Get computer properties from Active Directory

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
T-Cornett
Asked:
T-Cornett
  • 2
  • 2
  • 2
  • +1
4 Solutions
 
Glen KnightCommented:
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
 
KenMcFCommented:
You will need to pull these attributes from AD.

operatingSystem
operatingSystemVersion
operatingSystemServicePack
0
 
CAGdorfCommented:
You can use remote scanning tools as well. We use Spiceworks its free and lets you report off that information as well.
0
Veeam Disaster Recovery in Microsoft Azure

Veeam PN for Microsoft Azure is a FREE solution designed to simplify and automate the setup of a DR site in Microsoft Azure using lightweight software-defined networking. It reduces the complexity of VPN deployments and is designed for businesses of ALL sizes.

 
Glen KnightCommented:
I stand corrected, thanks KenMcF.

However, I stand by the rest of my post ;)
0
 
KenMcFCommented:
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
 
T-CornettAuthor Commented:
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
 
T-CornettAuthor Commented:
I am awarding each of you 50 points for trying to help me.
0

Featured Post

Problems using Powershell and Active Directory?

Managing Active Directory does not always have to be complicated.  If you are spending more time trying instead of doing, then it's time to look at something else. For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why

  • 2
  • 2
  • 2
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now