Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Vb script to find user from AD

Posted on 2006-11-06
13
Medium Priority
?
467 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
Migrating Your Company's PCs

To keep pace with competitors, businesses must keep employees productive, and that means providing them with the latest technology. This document provides the tips and tricks you need to help you migrate an outdated PC fleet to new desktops, laptops, and tablets.

 
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 150 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

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.

Question has a verified solution.

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

So you have two Windows Servers and you have a directory/folder/files on one that you'd like to mirror to the other?  You don't really want to deal with DFS or a 3rd party solution like Doubletake. You can use Robocopy from the Windows Server 200…
While rebooting windows server 2003 server , it's showing "active directory rebuilding indices please wait" at startup. It took a little while for this process to complete and once we logged on not all the services were started so another reboot is …
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…

670 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