Solved

Vb script to find user from AD

Posted on 2006-11-06
13
461 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
  • 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 70

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
Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

 
LVL 70

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 70

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 70

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 70

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 70

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 70

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

NAS Cloud Backup Strategies

This article explains backup scenarios when using network storage. We review the so-called “3-2-1 strategy” and summarize the methods you can use to send NAS data to the cloud

Question has a verified solution.

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

Organizations create, modify, and maintain huge amounts of data to help their businesses earn money and generally function.  Typically every network user within an organization has a bit of disk space to store in process items and personal files.   …
ADCs have gained traction within the last decade, largely due to increased demand for legacy load balancing appliances to handle more advanced application delivery requirements and improve application performance.
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

860 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