Title: [ActiveDir] ADSI vbscript and LDAP find

Thank you very much – and everyone else who responded so quickly!!

 


From: Michael B. Smith [mailto:[EMAIL PROTECTED]
Sent: Monday, November 03, 2003 10:04 AM
To: [EMAIL PROTECTED]
Subject: RE: [ActiveDir] ADSI vbscript and LDAP find

 

This shows all users. Change the strQuery to search for a particular user.

 

option explicit
Dim oRootDSE 'As IADs
Dim objUser 'As IADsUser
Dim oConnection 'As New ADODB.Connection
Dim oCommand 'As New ADODB.Command
Dim RS 'As ADODB.Recordset
Dim strQuery 'As String,
Dim newattrib 'As String
Dim varDomainNC 'As Variant

 


'On Error Resume Next

 

' Get the Configuration Naming Context
Set oRootDSE = GetObject("
LDAP://RootDSE")
varDomainNC = oRootDSE.Get("defaultNamingContext")
wscript.echo varDomainNC

 

' Open the Connection
set oConnection = Wscript.CreateObject("ADODB.Connection")
oConnection.Provider = "ADsDSOObject"
oConnection.Open "ADs Provider"

 

'Build a query to find all mail enabled Users that do not have
'extensionattribute2 set
strQuery = "<LDAP://" & varDomainNC & ">;(&(objectClass=user)(objectCategory=person));adspath,cn;subtree"

 

set oCommand = Wscript.CreateObject ("ADODB.Command")
oCommand.ActiveConnection = oConnection
oCommand.CommandText = strQuery
Set RS = oCommand.Execute

 

If RS.RecordCount = 0 Then
    Wscript.echo "No mailbox enabled Users found"
Else
    While Not RS.EOF
        Set objUser = GetObject(RS.Fields("adspath"))
        Wscript.echo objUser.cn 

        RS.MoveNext
    Wend
End If
Set oRootDSE = Nothing
Set objUser = Nothing
RS.Close
set RS = Nothing

 


From: Rich Milburn [mailto:[EMAIL PROTECTED]
Sent: Monday, November 03, 2003 10:53 AM
To: [EMAIL PROTECTED]
Subject: [ActiveDir] ADSI vbscript and LDAP find

I've tried finding the answer to this and it's hiding from me (I bet 15 people will respond with a link I overlooked!!)

I want to pull a user object from AD in vbscript by typing a login name in a box, or passing it as a parameter... but I'm having trouble finding a way to do this without either having to type the full DN or know what OU the user is in.  It seems easy but I've spent way too much time on it...

Here's the code:

strUser = InputBox("Enter object name to search for","Search for object")

Set objUser = GetObject("LDAP://CN=" & strUser & ",DC=domain,DC=com")

WScript.Echo objUser.userPrincipalName

This works if I add CN=Users or OU=___ and the object is in that container, but otherwise it just says object not found on the server.  (oh and WScript.Echo is not the goal here, just a test J)

Thanks -

Rich

-------APPLEBEE'S INTERNATIONAL, INC. CONFIDENTIALITY NOTICE-------  PRIVILEGED / CONFIDENTIAL INFORMATION may be contained in this message or any attachments. This information is strictly confidential and may be subject to attorney-client privilege. This message is intended only for the use of the named addressee. If you are not the intended recipient of this message, unauthorized forwarding, printing, copying, distribution, or using such information is strictly prohibited and may be unlawful. If you have received this in error, you should kindly notify the sender by reply e-mail and immediately destroy this message. Unauthorized interception of this e-mail is a violation of federal criminal law. Applebee's International, Inc. reserves the right to monitor and review the content of all messages sent to and from this e-mail address. Messages sent to or from this e-mail address may be stored on the Applebee's International, Inc. e-mail system.

-------APPLEBEE'S INTERNATIONAL, INC. CONFIDENTIALITY NOTICE------- PRIVILEGED / CONFIDENTIAL INFORMATION may be contained in this message or any attachments. This information is strictly confidential and may be subject to attorney-client privilege. This message is intended only for the use of the named addressee. If you are not the intended recipient of this message, unauthorized forwarding, printing, copying, distribution, or using such information is strictly prohibited and may be unlawful. If you have received this in error, you should kindly notify the sender by reply e-mail and immediately destroy this message. Unauthorized interception of this e-mail is a violation of federal criminal law. Applebee's International, Inc. reserves the right to monitor and review the content of all messages sent to and from this e-mail address. Messages sent to or from this e-mail address may be stored on the Applebee's International, Inc. e-mail system.

Reply via email to