AD User Verify

Script takes a proposed username from an InputBox and checks it against AD to see if the username is currently in use.

Source Code

This script has not been checked by Spiceworks. Please understand the risks before using it.

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

43

44

45

46

47

48

49

' ADUserVerify' Script takes username from inputbox and queries AD to see if it exists' Bill Reid, 2011strInput=InputBox("AD Username:")ifUserExists(strInput,sDisName)thenwscript.echo"Found "&sDisNameelsewscript.echo"No account found for "&strInputendifFunctionUserExists(sUser,sDisName)DimoConn,oCMD,oRoot,sDNSDomain,sQuery,sFilter,oResultsUserExists=FalsesDisName=sUserOnErrorResumeNext' Use ADO to search the domain for all users.SetoConn=CreateObject("ADODB.Connection")SetoCMD=CreateObject("ADODB.Command")oConn.Provider="ADsDSOOBject"oConn.Open"Active Directory Provider"SetoCMD.ActiveConnection=oConn' Determine the DNS domain from the RootDSE object.SetoRoot=GetObject("LDAP://RootDSE")sDNSDomain=oRoot.Get("DefaultNamingContext")sFilter="(&(ObjectClass=user)(ObjectCategory=person)(samAccountName="&sUser&"))"sQuery="<LDAP://"&sDNSDomain&">;"&sFilter&";displayName;subtree"oCMD.CommandText=sQueryoCMD.Properties("Page Size")=100oCMD.Properties("Timeout")=30oCMD.Properties("Cache Results")=FalseSetoResults=oCMD.ExecuteDoUntiloResults.EOFifoResults.Fields("displayName")<>""thensDisName=oResults.Fields("displayName")UserExists=TrueEndifoResults.MoveNextLoopOnErrorGoto0EndFunction