locked
Retrieving Active Directory Schema Version RRS feed

  • Question

  • Hi, I'm having problems retrieving the Active Directory Schema version from Active Directory using vb.net.

    I've tried the following code but it doesn't do anything...

            Dim theRootEntry As DirectoryEntry
            Dim SchemaVersionLevel As Object
            Dim theNamingContext As Object

            theRootEntry = New DirectoryServices.DirectoryEntry("LDAP://RootDSE")
            theNamingContext = theRootEntry.Properties("rootDomainNamingContext").Value
            theRootEntry = New DirectoryEntry("LDAP://CN=Schema,CN=Configuration," & theNamingContext)
            SchemaVersionLevel = theRootEntry.Properties("objectVersion").Value

    Can anyone tell me where I'm going wrong?

    Sunday, March 27, 2016 1:23 PM

Answers

  • Hi Li,

    Thanks for all the help, I've now worked out how to Retrieve the Active Directory Schema version now with the following code...

            Dim RootDSE As DirectoryEntry
            Dim SchemaContext As String
            Dim oSchema As New DirectoryEntry()
            Dim SchemaVersion as Object

            RootDSE = New DirectoryServices.DirectoryEntry("LDAP://RootDSE")
            SchemaContext = RootDSE.Properties("SchemaNamingContext").Value
            oSchema.Path = "LDAP://" & SchemaContext
            SchemaVersion = oSchema.InvokeGet("objectVersion")
            oSchema.Close()



    Tuesday, March 29, 2016 12:04 PM

All replies

  • Hi BadzMaru8,

    >>I've tried the following code but it doesn't do anything

    Have you used PowerShell to tested whether following code is work or not?

    dsquery * cn=schema,cn=configuration,dc=yourdomainname,dc=local -scope base -attr objectVersion

    If the command could not work either, I think Remote Server Administration Tools is not intalled on your machine. Please download and install it and run your code again later.
    https://support.microsoft.com/en-us/kb/2693643

    Best Regards,
    Li Wang


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Monday, March 28, 2016 3:02 AM
  • Hi Li, thanks for the replay, I've tried the dsquery and that works and I know RSAT is enabled :)
    Monday, March 28, 2016 1:15 PM
  • Hi BadzMaru8,

    Change your code as following.

    theRootEntry = New DirectoryEntry("LDAP://CN=Allowed-Attributes-Effective,CN=Schema,CN=Configuration,DC=local," & theNamingContext)

    If this could not work, I suggest you run the PowerShell command using VB.net and get result from it. For how to calling a powershell script form vb.net code, link below is for your reference.
    https://blogs.msdn.microsoft.com/zainnab/2008/07/26/calling-a-powershell-script-from-your-net-code/

    Best Regards,
    Li Wang


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Tuesday, March 29, 2016 8:28 AM
  • Hi Li,

    Thanks for all the help, I've now worked out how to Retrieve the Active Directory Schema version now with the following code...

            Dim RootDSE As DirectoryEntry
            Dim SchemaContext As String
            Dim oSchema As New DirectoryEntry()
            Dim SchemaVersion as Object

            RootDSE = New DirectoryServices.DirectoryEntry("LDAP://RootDSE")
            SchemaContext = RootDSE.Properties("SchemaNamingContext").Value
            oSchema.Path = "LDAP://" & SchemaContext
            SchemaVersion = oSchema.InvokeGet("objectVersion")
            oSchema.Close()



    Tuesday, March 29, 2016 12:04 PM