Follow along with the video below to see how to install our site as a web app on your home screen.
Note: This feature may not be available in some browsers.
Enumerate
Sub Enumerate ()
strADsPath = "LDAP://dc=your_domain,dc=com"
' replace the above line with this one to walk the "users" sub tree
' of the Active Directory
' WScript.STDOUT.WriteLine "+" & strADsPath
WalkTree strADsPath, "|-->"
End Sub
' recursive function to walk down through the tree
Sub WalkTree(strPath, buffer)
Set oContainer = GetObject(strPath)
For Each object In oContainer
If object.Class = "computer" Then
WScript.STDOUT.WriteLine buffer & object.Name
Else
Set oClass = GetObject(object.Schema)
If (oClass.Container) and object.Schema = "LDAP://schema/organizationalUnit" Then
WalkTree object.ADsPath, buffer & object.Name & "| "
End If
End If
Next
End Sub
objToFind = InputBox("Enter Computer Name to Locate","What Should I Find?")
ExecuteSearch = SearchDistinguishedName(objToFind)
Public Function SearchDistinguishedName(ByVal vSAN)
Const ADS_SCOPE_SUBTREE = 2
Dim oRootDSE, oConnection, oCommand, oRecordSet
Set oRootDSE = GetObject("LDAP://rootDSE")
Set oConnection = CreateObject("ADODB.Connection")
oConnection.Open "Provider=ADsDSOObject;"
Set objCommand = CreateObject("ADODB.Command")
objCommand.ActiveConnection = oConnection
ldstring = "'LDAP://" & oRootDSE.get("defaultNamingContext") & "'"
objCommand.CommandText = "Select Name, distinguishedName from "& ldstring & " where objectClass='computer'"
objCommand.Properties("Page Size") = 1000
objCommand.Properties("Timeout") = 30
objCommand.Properties("Searchscope") = ADS_SCOPE_SUBTREE
objCommand.Properties("Cache Results") = False
Set objRecordSet = objCommand.Execute
objRecordSet.MoveFirst
Do Until objRecordSet.EOF
If lcase(objRecordSet.Fields("Name").Value) = lcase(vSan) Then
Wscript.Echo "Computer Name: " & objRecordSet.Fields("Name").Value & vbCrLf _
& "Location: " & objRecordSet.Fields("distinguishedName").Value
'Wscript.Quit
End If
objRecordSet.MoveNext
Loop
End Function
Dim wshShell, wshNetwork
Dim strComputerName
' Create Global Objects
Set wshShell = CreateObject("WScript.Shell")
Set wshNetwork = CreateObject("WScript.Network")
' Initialize Variables
strComputerName = wshNetwork.ComputerName
wscript.echo "Computer DN: " & GetDN
Function GetDN()
' Use the NameTranslate object to convert the NT name of the computer to
' the Distinguished name required for the LDAP provider. Computer names
' must end with "$". Returns comma delimited string to calling code.
Dim objTrans, objDomain
' Constants for the NameTranslate object.
Const ADS_NAME_INITTYPE_GC = 3
Const ADS_NAME_TYPE_NT4 = 3
Const ADS_NAME_TYPE_1779 = 1
Set objTrans = CreateObject("NameTranslate")
Set objDomain = getObject("LDAP://rootDse")
objTrans.Init ADS_NAME_INITTYPE_GC, ""
objTrans.Set ADS_NAME_TYPE_NT4, wshNetwork.UserDomain & "\" _
& strComputerName & "$"
GetDN = objTrans.Get(ADS_NAME_TYPE_1779)
'Set DN to upper Case
GetDN = UCase(GetDN)
End Function