Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Disable Users In AD From A Text File 1

Status
Not open for further replies.

LBMCreation

Technical User
Jul 5, 2011
9
GB
Hi All,

I am new to this forum and dont know if this has been answered before. But I am trying to make a script which takes the "CN" name from a text file e.g

Example.txt - Name1
Name2
Name3

But the problem I am getting is the only script I could find uses the DN name of each user.

The reason I would like to use a simple text/xls file and just have the names in it is because at work we have a list sent out each day and all it has on it is names of users. The list is Users who have left the business so their accounts need disabling, hide from GAL, remove from all groups, and moved into a different OU.

Sorry again if this has been anserwed before but like I said its my first post on these forums.

Thanks In Advance

Mark
 
Update:

I have found the following script on this forum.

************************************************************

'on error resume next
'Option explicit

Dim strOutfile, strSDesk, strDisOu, oshell, strUserName, strChange
Dim objRootDSE, DNSDomain, objConnection, objCommand, objRecordset
Dim strADsPath, strUserInfo, strMemberOf, strFileName, rdns
Dim strOUs, strService, strNewOu, objOUobj

' Read Usernames from Text File
Const ForReading = 1
Const ForAppending = 8
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objTextFile = objFSO.OpenTextFile _
("UserAccountsToDisable.txt", ForReading)
Do Until objTextFile.AtEndOfStream
strUserName = objTextFile.Readline
arrTargets = Split(strUserName , ",")
For Each strUserName in arrTargets

' Determine the DNS domain from the RootDSE object.

Set objRootDSE = GetObject("LDAP://RootDSE")
strDNSDomain = objRootDSE.Get("DefaultNamingContext")
Set objDomain = GetObject("LDAP://" & ADsPath)
Set objConnection = CreateObject("ADODB.Connection")
objConnection.Open "Provider=ADsDSOObject;"
Set objCommand = CreateObject("ADODB.Command")
objCommand.ActiveConnection = objConnection

wscript.echo strUserName

objCommand.CommandText = "<LDAP://" & strDNSDomain & ">;" & "(&(objectCategory=User)(cn=" & strUserName &"))" & ";ADsPath;subtree"

Wscript.echo strDNSDomain
wscript.echo objCommand.CommandText

'get a list of users with this name'

Set objRecordset = objCommand.Execute
If objrecordset.recordcount = 0 then

Set objLogFile = objFSO.OpenTextFile _
("UserNameNotFound.txt", ForAppending, True)
objLogFile.WriteLine

End If

****************************************************

Problem is I am getting a expected Next error when I try and run it. Can someone point out where I am going wrong?

Many Thanks

Mark
 
You're missing a Next and a Loop instructions ...

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Sorry, I am a new to VBS, can you explain where I have to place the Next & Loop instructions please.

Many Thanks
 
I have found the following script on this forum
Where ?

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top