AD Query

OU.vbs

cscript OU.vbs

Save the following file as OU.vbs on your Windows laptop...

Set objSysInfo = CreateObject("ADSystemInfo")
strUserName = objSysInfo.UserName
strCompName = objSysInfo.ComputerName
Set objUser = GetObject("LDAP://" & strUserName)
strOUName = objUser.Parent
Set objComp = GetObject("LDAP://" & strCompName)
Set objOU = GetObject(strOUName)
Wscript.Echo objSysInfo.ComputerName
Wscript.Echo objSysInfo.UserName
Wscript.Echo objUser.Parent
Wscript.Echo objOU.distinguishedName
Wscript.Echo objComp.operatingSystem
Wscript.Echo objComp.operatingSystemServicePack

SearchAD.vbs

cscript SearchAD.vbs

Save the following script as SearchAD.vbs on your Windows laptop...

'SearchAD.vbs
On Error Resume Next
' Connect to the LDAP server's root object
Set objRootDSE = GetObject("LDAP://RootDSE")
strDNSDomain = objRootDSE.Get("defaultNamingContext")
strTarget = "LDAP://" & strDNSDomain
wscript.Echo "Starting search from " & strTarget
' Connect to Ad Provider
Set objConnection = CreateObject("ADODB.Connection")
objConnection.Provider = "ADsDSOObject"
objConnection.Open "Active Directory Provider"
Set objCmd =   CreateObject("ADODB.Command")
Set objCmd.ActiveConnection = objConnection 
' Show only computers
'objCmd.CommandText = "SELECT Name, ADsPath FROM '" & strTarget & "' WHERE objectCategory = 'computer'"
' or show only users
objCmd.CommandText = "SELECT Name, ADsPath FROM '" & strTarget & "' WHERE objectCategory = 'user'"
' or show only groups
' objCmd.CommandText = "SELECT Name, ADsPath FROM '" & strTarget & "' WHERE objectCategory = 'group'"
Const ADS_SCOPE_SUBTREE = 2
objCmd.Properties("Page Size") = 100
objCmd.Properties("Timeout") = 30
objCmd.Properties("Searchscope") = ADS_SCOPE_SUBTREE
objCmd.Properties("Cache Results") = False
Set objRecordSet = objCmd.Execute
' Iterate through the results
objRecordSet.MoveFirst
Do Until objRecordSet.EOF
   sComputerName = objRecordSet.Fields("Name")
   wscript.Echo sComputerName
   objRecordSet.MoveNext
Loop

userinfo.vbs

cscript userinfo.vbs

To create, save the following script as userinfo.vbs on your Windows laptop...

'userinfo.vbs

' Usage:
'       cscript //Nologo userinfo.vbs

' List User properties as displayed in ADUC

On Error Resume Next
Dim objSysInfo, objUser
Set objSysInfo = CreateObject("ADSystemInfo")

' Currently logged in User
Set objUser = GetObject("LDAP://" & objSysInfo.UserName)
' or specific user:
'Set objUser = GetObject("LDAP://CN=yourusername,OU=Users,DC=yourdomain,DC=com")

WScript.Echo "DN: " & objUser.distinguishedName

WScript.Echo ""
WScript.Echo "GENERAL"
WScript.Echo "First name: " & objUser.givenName
'WScript.Echo "First name: " & objUser.FirstName
WScript.Echo "Initials: " & objUser.initials
WScript.Echo "Last name: " & objUser.sn
'WScript.Echo "Last name: " & objUser.LastName
WScript.Echo "Display name: " & objUser.displayName
'WScript.Echo "Display name: " & objUser.FullName
WScript.Echo "Description: " & objUser.description
WScript.Echo "Office: " & objUser.physicalDeliveryOfficeName
WScript.Echo "Telephone number: " & objUser.telephoneNumber
WScript.Echo "Other Telephone numbers: " & objUser.otherTelephone
WScript.Echo "Email: " & objUser.mail
'WScript.Echo "Email: " & objUser.EmailAddress
WScript.Echo "Web page: " & objUser.wWWHomePage
WScript.Echo "Other Web pages: " & objUser.url
WScript.Echo ""
WScript.Echo "ADDRESS"
WScript.Echo "Street: " & objUser.streetAddress
WScript.Echo "P.O. Box: " & objUser.postOfficeBox
WScript.Echo "City: " & objUser.l
WScript.Echo "State/province: " & objUser.st
WScript.Echo "Zip/Postal Code: " & objUser.postalCode
WScript.Echo "Country/region: " & objUser.countryCode
'WScript.Echo "Country/region: " & objUser.c    '(ISO 4217)
WScript.Echo ""
WScript.Echo "ACCOUNT"
WScript.Echo "User logon name: " & objUser.userPrincipalName
WScript.Echo "pre-Windows 2000 logon name: " & objUser.sAMAccountName
WScript.Echo "AccountDisabled: " & objUser.AccountDisabled
'WScript.Echo "Account Control #: " & objUser.userAccountControl
WScript.Echo "Logon Hours: " & objUser.logonHours
WScript.Echo "Logon On To (Logon Workstations): " & objUser.userWorkstations
'WScript.Echo "User must change password at next logon: " & objUser.pwdLastSet
WScript.Echo "User cannot change password: " & objUser.userAccountControl
WScript.Echo "Password never expires: " & objUser.userAccountControl
WScript.Echo "Store password using reversible encryption: " & objUser.userAccountControl
'WScript.Echo "Account expires end of (date): " & objUser.accountExpires
WScript.Echo ""
WScript.Echo "PROFILE"
WScript.Echo "Profile path: " & objUser.profilePath
'WScript.Echo "Profile path: " & objUser.Profile
WScript.Echo "Logon script: " & objUser.scriptPath
WScript.Echo "Home folder, local path: " & objUser.homeDirectory
WScript.Echo "Home folder, Connect, Drive: " & objUser.homeDrive
WScript.Echo "Home folder, Connect, To:: " & objUser.homeDirectory
WScript.Echo ""
WScript.Echo "TELEPHONE"
WScript.Echo "Home: " & objUser.homePhone
WScript.Echo "Other Home phone numbers: " & objUser.otherHomePhone
WScript.Echo "Pager: " & objUser.pager
WScript.Echo "Other Pager numbers: " & objUser.otherPager
WScript.Echo "Mobile: " & objUser.mobile
WScript.Echo "Other Mobile numbers: " & objUser.otherMobile
WScript.Echo "Fax: " & objUser.facsimileTelephoneNumber
WScript.Echo "Other Fax numbers: " & objUser.otherFacsimileTelephoneNumber
WScript.Echo "IP phone: " & objUser.ipPhone
WScript.Echo "Other IP phone numbers: " & objUser.otherIpPhone
WScript.Echo "Notes: " & objUser.info
WScript.Echo ""
WScript.Echo "ORGANISATION"
WScript.Echo "Title: " & objUser.title
WScript.Echo "Department: " & objUser.department
WScript.Echo "Company: " & objUser.company
WScript.Echo "Manager: " & objUser.manager