• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 473
  • Last Modified:

Vb script to find user from AD

Need VB script to find user from AD .Get the user list from user.txt and the out put log to userthere.log
0
belranjan
Asked:
belranjan
  • 7
  • 5
1 Solution
 
MidnightOneCommented:
belranjan:

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

MidnightOne
0
 
Chris DentPowerShell DeveloperCommented:

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

Chris
0
 
belranjanAuthor 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
0
Cloud Class® Course: Python 3 Fundamentals

This course will teach participants about installing and configuring Python, syntax, importing, statements, types, strings, booleans, files, lists, tuples, comprehensions, functions, and classes.

 
Chris DentPowerShell DeveloperCommented:

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
 
Chris DentPowerShell DeveloperCommented:

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

Chris
0
 
belranjanAuthor 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)
0
 
Chris DentPowerShell DeveloperCommented:

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
 
belranjanAuthor Commented:
I have modified this line strDomain = objNetwork.UserDomain to
strDomain = "mydomain.com"
BUT I HAVE GOT THE SAME OUTPUT
0
 
Chris DentPowerShell DeveloperCommented:

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

Chris
0
 
belranjanAuthor Commented:
I can't follow what u r saying .Can u pls explain me clear
0
 
Chris DentPowerShell DeveloperCommented:

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

Thanks,

Chris
0
 
belranjanAuthor Commented:
sorry for late

nothing all user id like this

user1
user2
user3
0
 
Chris DentPowerShell DeveloperCommented:

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
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: SQL Server Core 2016

This course will introduce you to SQL Server Core 2016, as well as teach you about SSMS, data tools, installation, server configuration, using Management Studio, and writing and executing queries.

  • 7
  • 5
Tackle projects and never again get stuck behind a technical roadblock.
Join Now