|
fracine -> RE: Not able to display all fields (4/17/2008 8:28:19 AM)
|
I have a problem with the and name='strComputername'", I got an error message on line 28. How would I resolve this. The job you did is simply incredible! 'On Error Resume Next Set objShell = CreateObject("WScript.Shell") strComputername = objShell.ExpandEnvironmentStrings("%computername%") Wscript.echo strComputername Const ADS_SCOPE_SUBTREE = 2 Set objConnection = CreateObject("ADODB.Connection") Set objCommand = CreateObject("ADODB.Command") objConnection.Provider = "ADsDSOObject" objConnection.Open "Active Directory Provider" Set objCommand.ActiveConnection = objConnection dim root, sADSPath 'Get the default ADsPath for the domain to search. Set root = GetObject("LDAP://rootDSE") sADSPath = root.Get("defaultNamingContext") objCommand.CommandText = "SELECT Name, Location, displayName, distinguishedName," & _ "operatingSystem, operatingSystemServicePack," & _ "sAMAccountName, whenCreated FROM 'LDAP://"& sADSPath &"'" & _ " WHERE objectClass='computer' and name='strComputername'" objCommand.Properties("Page Size") = 1000 objCommand.Properties("Timeout") = 60 objCommand.Properties("Searchscope") = ADS_SCOPE_SUBTREE objCommand.Properties("Cache Results") = False 'objCommand.Properties("Size Limit") = 10 'debug, limit to 10 results Set objRecordSet = objCommand.Execute objRecordSet.MoveFirst Do Until objRecordSet.EOF Wscript.Echo "Computer Name: " & objRecordSet.Fields("Name").Value Wscript.Echo "Location: " & objRecordSet.Fields("Location").Value Wscript.Echo "displayName: " & objRecordSet.Fields("displayName").Value strDN = objRecordSet.Fields("distinguishedName").Value Wscript.Echo "distinguishedName: " & strDN Wscript.Echo "objectGUID: " & GetGUID(strDN) Wscript.Echo "objectSid: " & GetSid(strDN) Wscript.Echo "operatingSystem: " & objRecordSet.Fields("operatingSystem").Value Wscript.Echo "operatingSystemServicePack: " & objRecordSet.Fields("operatingSystemServicePack").Value Wscript.Echo "sAMAccountName: " & objRecordSet.Fields("sAMAccountName").Value Wscript.Echo "whenCreated: " & objRecordSet.Fields("whenCreated").Value objRecordSet.MoveNext Loop 'most of these routines come from or are based on RL Mueller code, http://www.rlmueller.net/ Function GetSid(dn) Set objUser = GetObject("LDAP://" & dn ) ' Retrieve SID and convert to hex string, then to decimal string. arrSid = objUser.objectSid strSidHex = OctetToHexStr(arrSid) GetSid = HexStrToDecStr(strSidHex) End Function Function GetGUID(dn) Set objUser = GetObject("LDAP://" & dn ) arrbytGuid = objUser.objectGuid strHexGuid = OctetToHexStr(arrbytGuid) 'Wscript.Echo "User Guid in hex string format: " & strHexGuid strGuid = HexGuidToGuidStr(strHexGuid) 'Wscript.Echo "User Guid in display format: " & strGuid GetGUID = strGUID End Function Function OctetToHexStr(arrbytOctet) 'Mueller ' Function to convert OctetString (byte array) to Hex string. Dim k OctetToHexStr = "" For k = 1 To Lenb(arrbytOctet) OctetToHexStr = OctetToHexStr _ & Right("0" & Hex(Ascb(Midb(arrbytOctet, k, 1))), 2) Next End Function Function HexStrToDecStr(strSid) 'Mueller ' Function to convert hex Sid to decimal (SDDL) Sid. Dim arrbytSid, lngTemp, j ReDim arrbytSid(Len(strSid)/2 - 1) For j = 0 To UBound(arrbytSid) arrbytSid(j) = CInt("&H" & Mid(strSid, 2*j + 1, 2)) Next HexStrToDecStr = "S-" & arrbytSid(0) & "-" _ & arrbytSid(1) & "-" & arrbytSid(8) lngTemp = arrbytSid(15) lngTemp = lngTemp * 256 + arrbytSid(14) lngTemp = lngTemp * 256 + arrbytSid(13) lngTemp = lngTemp * 256 + arrbytSid(12) HexStrToDecStr = HexStrToDecStr & "-" & CStr(lngTemp) lngTemp = arrbytSid(19) lngTemp = lngTemp * 256 + arrbytSid(18) lngTemp = lngTemp * 256 + arrbytSid(17) lngTemp = lngTemp * 256 + arrbytSid(16) HexStrToDecStr = HexStrToDecStr & "-" & CStr(lngTemp) lngTemp = arrbytSid(23) lngTemp = lngTemp * 256 + arrbytSid(22) lngTemp = lngTemp * 256 + arrbytSid(21) lngTemp = lngTemp * 256 + arrbytSid(20) HexStrToDecStr = HexStrToDecStr & "-" & CStr(lngTemp) lngTemp = arrbytSid(25) lngTemp = lngTemp * 256 + arrbytSid(24) HexStrToDecStr = HexStrToDecStr & "-" & CStr(lngTemp) End Function Function HexGuidToGuidStr(strGuid) ' Function to convert Hex Guid to display form. Dim k HexGuidToGuidStr = "" For k = 1 To 4 HexGuidToGuidStr = HexGuidToGuidStr & Mid(strGuid, 9 - 2*k, 2) Next HexGuidToGuidStr = HexGuidToGuidStr & "-" For k = 1 To 2 HexGuidToGuidStr = HexGuidToGuidStr & Mid(strGuid, 13 - 2*k, 2) Next HexGuidToGuidStr = HexGuidToGuidStr & "-" For k = 1 To 2 HexGuidToGuidStr = HexGuidToGuidStr & Mid(strGuid, 17 - 2*k, 2) Next HexGuidToGuidStr = HexGuidToGuidStr & "-" & Mid(strGuid, 17, 4) HexGuidToGuidStr = HexGuidToGuidStr & "-" & Mid(strGuid, 21) End Function
|
|
|
|