Solved

Vb script to find user from AD

Posted on 2006-11-06
13
463 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
0
Comment
Question by:belranjan
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 7
  • 5
13 Comments
 
LVL 26

Expert Comment

by:MidnightOne
ID: 17881217
belranjan:

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

MidnightOne
0
 
LVL 71

Expert Comment

by:Chris Dent
ID: 17881366

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

Chris
0
 

Author Comment

by:belranjan
ID: 17887484
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
0
Major Incident Management Communications

Major incidents and IT service outages cost companies millions. Often the solution to minimizing damage is automated communication. Find out more in our Major Incident Management Communications infographic.

 
LVL 71

Expert Comment

by:Chris Dent
ID: 17908313

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
0
 
LVL 71

Expert Comment

by:Chris Dent
ID: 17908319

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

Chris
0
 

Author Comment

by:belranjan
ID: 17913346
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)
0
 
LVL 71

Expert Comment

by:Chris Dent
ID: 17913365

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
0
 

Author Comment

by:belranjan
ID: 17913488
I have modified this line strDomain = objNetwork.UserDomain to
strDomain = "mydomain.com"
BUT I HAVE GOT THE SAME OUTPUT
0
 
LVL 71

Expert Comment

by:Chris Dent
ID: 17913502

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

Chris
0
 

Author Comment

by:belranjan
ID: 17914571
I can't follow what u r saying .Can u pls explain me clear
0
 
LVL 71

Expert Comment

by:Chris Dent
ID: 17914721

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

Thanks,

Chris
0
 

Author Comment

by:belranjan
ID: 17938648
sorry for late

nothing all user id like this

user1
user2
user3
0
 
LVL 71

Accepted Solution

by:
Chris Dent earned 50 total points
ID: 17960796

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
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Preface Having the need * to contact many different companies with different infrastructures * do remote maintenance in their network required us to implement a more flexible routing solution. As RAS, PPTP, L2TP and VPN Client connections are no…
Restoring deleted objects in Active Directory has been a standard feature in Active Directory for many years, yet some admins may not know what is available.
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

734 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question