We help IT Professionals succeed at work.

We've partnered with Certified Experts, Carl Webster and Richard Faulkner, to bring you two Citrix podcasts. Learn about 2020 trends and get answers to your biggest Citrix questions!Listen Now

x

Vb script to find user from AD

belranjan
belranjan asked
on
Medium Priority
481 Views
Last Modified: 2008-03-06
Need VB script to find user from AD .Get the user list from user.txt and the out put log to userthere.log
Comment
Watch Question

belranjan:

What information are you looking for, precisely? Their existence, their location in the AD tree?

MidnightOne
Chris DentPowerShell Developer
CERTIFIED EXPERT
Top Expert 2010

Commented:

What do you have in user.txt and what do you want in userthere.log?

Chris

Author

Commented:
i have the user id list (user.txt) to check is the user are created in AD if yes i shoud get the log created if not i should get the user not created in userther.log
Chris DentPowerShell Developer
CERTIFIED EXPERT
Top Expert 2010

Commented:

Then this should do...


Set objFileSystem = CreateObject("Scripting.FileSystemObject")

Set objFile = objFileSystem.GetFile("user.txt")
Set objStream = objFile.OpenAsTextStream(1, 0)

Set objReport = objFileSystem.OpenTextFile("userthere.log", 2, True, 0)

Set objNetwork = CreateObject("WScript.Network")
strDomain = objNetwork.UserDomain
Set objNetwork = Nothing

Do While Not objStream.AtEndOfStream
      strUser = objStream.ReadLine
      If strUser <> "" Then
            On Error Resume Next
            Err.Clear
            Set objUser = GetObject("WinNT://" & strDomain & "/" & strUser & ", user")
            If Err.Number = 0 Then
                  objReport.WriteLine strUser & VbTab & "Found"
            Else
                  objReport.WriteLine strUser & VbTab & "Not Found"
            End If
            Set objUser = Nothing
            On Error Goto 0
      End If
Loop
Chris DentPowerShell Developer
CERTIFIED EXPERT
Top Expert 2010

Commented:

Oh and sorry for the late reply, lost track a bit...

Chris

Author

Commented:
How to test this script.let me know need to add any thing about my domain name

I have creted user.txt in c:\ drive and add user id (domain\username)
And copyed u r script as ad.vbs
I have run the scritp i got the log output as (domain\user name00000)
Chris DentPowerShell Developer
CERTIFIED EXPERT
Top Expert 2010

Commented:

If you're listing them in the text file as "domain\username" then it would need to be changed. Would it be possible to have them listed just as usernames?

There are a number of ways to validate whether the account exists or not, the WinNT interface is probably the easiest however it's certainly not the only one.

Chris

Author

Commented:
I have modified this line strDomain = objNetwork.UserDomain to
strDomain = "mydomain.com"
BUT I HAVE GOT THE SAME OUTPUT
Chris DentPowerShell Developer
CERTIFIED EXPERT
Top Expert 2010

Commented:

Did you change the input so it didn't include the domain name?

Chris

Author

Commented:
I can't follow what u r saying .Can u pls explain me clear
Chris DentPowerShell Developer
CERTIFIED EXPERT
Top Expert 2010

Commented:

Can you paste a sample of what you have in users.txt?

Thanks,

Chris

Author

Commented:
sorry for late

nothing all user id like this

user1
user2
user3
PowerShell Developer
CERTIFIED EXPERT
Top Expert 2010
Commented:

Hmm odd, there doesn't seem to be anything wrong, the input format is what I expected. The output file is showing "domain\user name00000"? If so, there's something wrong somewhere, there's nothing in the script I gave you that would produce that output.

Chris

Not the solution you were looking for? Getting a personalized solution is easy.

Ask the Experts
Access more of Experts Exchange with a free account
Thanks for using Experts Exchange.

Create a free account to continue.

Limited access with a free account allows you to:

  • View three pieces of content (articles, solutions, posts, and videos)
  • Ask the experts questions (counted toward content limit)
  • Customize your dashboard and profile

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.