supportemea
asked on
VBScript to Return OU where User account is located
Hey Guys,
Im trying to create a generic login script for a domain that has about 5 OU's of where users are located.
Im having a hard time finding a script that will return the OU of where a user account is located
Im trying to create a generic login script for a domain that has about 5 OU's of where users are located.
Im having a hard time finding a script that will return the OU of where a user account is located
Hi there, for a logon script, this will give you the breakdown of the path for your current user account, so you can pick which element you are after and change the index in
strOU = arrOU(1)
to suit.
Regards,
Rob.
strOU = arrOU(1)
to suit.
Regards,
Rob.
Set objADSysInfo = CreateObject("ADSystemInfo")
arrOU = Split(objADSysInfo.UserName, ",")
strPath = "OU Path"
For intBit = LBound(arrOU) To UBound(arrOU)
strPath = strPath & VbCrLf & "Element " & intBit & ": " & arrOU(intBit)
Next
MsgBox strPath
strOU = arrOU(1)
MsgBox strOU
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
==========================
On Error Resume Next
Const ADS_SCOPE_SUBTREE = 2
Set objConnection = CreateObject("ADODB.Connec
Set objCommand = CreateObject("ADODB.Comman
objConnection.Provider = "ADsDSOObject"
objConnection.Open "Active Directory Provider"
Set objCommand.ActiveConnectio
FindUser = InputBox("Please Enter the UserName", "Find User OU")
If FindUser = "" Then
MsgBox("No UserName Was Added")
WScript.Quit
Else
strUser = FindUser
End If
objCommand.Properties("Pag
objCommand.Properties("Sea
objCommand.CommandText = _
"SELECT ADsPath FROM 'LDAP://dc="giveurdchere",
Set objRecordSet = objCommand.Execute
objRecordSet.MoveFirst
Do Until objRecordSet.EOF
Wscript.Echo objRecordSet.Fields("ADsPa
objRecordSet.MoveNext
Loop
==========================