Solved

Vb script to find user from AD

Posted on 2006-11-06
13
464 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
Visualize your virtual and backup environments

Create well-organized and polished visualizations of your virtual and backup environments when planning VMware vSphere, Microsoft Hyper-V or Veeam deployments. It helps you to gain better visibility and valuable business insights.

 
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

Webinar: Aligning, Automating, Winning

Join Dan Russo, Senior Manager of Operations Intelligence, for an in-depth discussion on how Dealertrack, leading provider of integrated digital solutions for the automotive industry, transformed their DevOps processes to increase collaboration and move with greater velocity.

Question has a verified solution.

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

by Batuhan Cetin In this article I will be guiding through the process of removing a failed DC metadata from Active Directory (hereafter, AD) using the ntdsutil tool in a Windows Server 2003 environment. These steps are not necessary in a Win…
I guess it is not common knowledge to most Wintel engineers/administrators: If you have an SNMP-based monitoring system in your environment (and it's common to have SNMP or Syslog) it's reasonably easy to enable monitoring of the Windows Event logs,…
If you're a developer or IT admin, you’re probably tasked with managing multiple websites, servers, applications, and levels of security on a daily basis. While this can be extremely time consuming, it can also be frustrating when systems aren't wor…
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor (https://www.adremsoft.com/). Top Charts is a view in which you can set seve…

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