stephenslong
01-11-2013, 08:24 AM
Hello
I have two functions in excel 2010. I found "ComputerDescription" online and it works fine. I attempted to copy/modify it to retrieve more information but my modified ("operatingSystem") version doesnt work. I'm not a complete novice but not an expert either. I feel like I'm just missing something. Can someone help please?
Function ComputerDescription(ComputerName) As String
Set objConnection = CreateObject("ADODB.Connection")
Set objCommand = CreateObject("ADODB.Command")
objConnection.Provider = "ADsDSOObject"
objConnection.Open "Active Directory Provider"
Set objCommand.ActiveConnection = objConnection
objCommand.Properties("Page Size") = 1000
objCommand.Properties("Searchscope") = 2
objCommand.CommandText = "SELECT description FROM 'LDAP://ou=R_Shared Services,dc=nortrax-inc,dc=com' WHERE name = '" & ComputerName & "' AND objectClass = 'computer'"
Set objRecordSet = objCommand.Execute
If objRecordSet.RecordCount < 1 Then
ComputerDescription = "No results found"
End If
objRecordSet.MoveFirst
Set myVal = objRecordSet.Fields("description")
Dim desc
For Each desc In myVal.Value
ComputerDescription = desc
Next
objRecordSet.Close
objConnection.Close
End Function
Function operatingSystem(ComputerName) As String
Set objConnection = CreateObject("ADODB.Connection")
Set objCommand = CreateObject("ADODB.Command")
objConnection.Provider = "ADsDSOObject"
objConnection.Open "Active Directory Provider"
Set objCommand.ActiveConnection = objConnection
objCommand.Properties("Page Size") = 1000
objCommand.Properties("Searchscope") = 2
objCommand.CommandText = "SELECT operatingSystem FROM 'LDAP://ou=R_Shared Services,dc=nortrax-inc,dc=com' WHERE name = '" & ComputerName & "' AND objectClass = 'computer'"
Set objRecordSet = objCommand.Execute
If objRecordSet.RecordCount < 1 Then
operatingSystem = "No results found"
End If
objRecordSet.MoveFirst
Set myVal = objRecordSet.Fields("operatingSystem")
Dim OS
For Each OS In myVal.Value
operatingSystem = OS
Next
objRecordSet.Close
objConnection.Close
End Function
I have two functions in excel 2010. I found "ComputerDescription" online and it works fine. I attempted to copy/modify it to retrieve more information but my modified ("operatingSystem") version doesnt work. I'm not a complete novice but not an expert either. I feel like I'm just missing something. Can someone help please?
Function ComputerDescription(ComputerName) As String
Set objConnection = CreateObject("ADODB.Connection")
Set objCommand = CreateObject("ADODB.Command")
objConnection.Provider = "ADsDSOObject"
objConnection.Open "Active Directory Provider"
Set objCommand.ActiveConnection = objConnection
objCommand.Properties("Page Size") = 1000
objCommand.Properties("Searchscope") = 2
objCommand.CommandText = "SELECT description FROM 'LDAP://ou=R_Shared Services,dc=nortrax-inc,dc=com' WHERE name = '" & ComputerName & "' AND objectClass = 'computer'"
Set objRecordSet = objCommand.Execute
If objRecordSet.RecordCount < 1 Then
ComputerDescription = "No results found"
End If
objRecordSet.MoveFirst
Set myVal = objRecordSet.Fields("description")
Dim desc
For Each desc In myVal.Value
ComputerDescription = desc
Next
objRecordSet.Close
objConnection.Close
End Function
Function operatingSystem(ComputerName) As String
Set objConnection = CreateObject("ADODB.Connection")
Set objCommand = CreateObject("ADODB.Command")
objConnection.Provider = "ADsDSOObject"
objConnection.Open "Active Directory Provider"
Set objCommand.ActiveConnection = objConnection
objCommand.Properties("Page Size") = 1000
objCommand.Properties("Searchscope") = 2
objCommand.CommandText = "SELECT operatingSystem FROM 'LDAP://ou=R_Shared Services,dc=nortrax-inc,dc=com' WHERE name = '" & ComputerName & "' AND objectClass = 'computer'"
Set objRecordSet = objCommand.Execute
If objRecordSet.RecordCount < 1 Then
operatingSystem = "No results found"
End If
objRecordSet.MoveFirst
Set myVal = objRecordSet.Fields("operatingSystem")
Dim OS
For Each OS In myVal.Value
operatingSystem = OS
Next
objRecordSet.Close
objConnection.Close
End Function