We help IT Professionals succeed at work.

DISABLE LISTE USERS

please How can I DISABLE the list of users in active directory  AND MODIFY THE DESCRIPTION
Comment
Watch Question

Right click on the user and click Disable.

If you have a 2008 DFL you can do this on multiple users by Ctrl Click then right click. Not 100% if you can do it on anything under a 2008 DFL however

Author

Commented:
it is not a good idea please I can a script to disable a liste of users and also change the descriptions
If the users are in different OU's or you want to process a large number of users from a text file, this can be done via vbscript. Let me know if that is what you require and I'll throw one together for you, otherwise Chompishk's suggestion is spot on.

Author

Commented:
yes Scottyworld it is the required idea but also please I want to add at the end of the description tag the date of the disabled user
THX  
Hey DRRAM,
Try the following vbs code.
Edit line 2 to reflect the location of your text file, which needs to contain the username you wish to modify.
The script will grab the current user account description and add -DISABLED <today's date> to the end of it
Then the account will be disabled
 
Const ForReading = 1
strTxtFile = "C:\temp\userlist.txt" 'input text file with list of users
Set fso = CreateObject("Scripting.FileSystemObject")
Set objFile = fso.OpenTextFile(strTxtFile, ForReading) 'open file for reading

'Set up the AD connection
Set rootDSE = GetObject("LDAP://RootDSE")
Set adoConnection = CreateObject("ADODB.Connection")
adoConnection.Provider = "ADSDSOObject"
adoConnection.Open "ADs Provider"

Do Until objFile.AtEndOfStream
	strUser = objFile.ReadLine
	ldapStr = "<LDAP://" & rootDSE.Get("defaultNamingContext") & ">;(&(objectCategory=Person)(objectClass=User)(samAccountName=" & strUser & "));ADsPath,description;subtree"
	Set adoRecord = adoConnection.Execute(ldapStr)
	If Not adoRecord.EOF Then
		'Grab the existing description field
		arrDesc = adoRecord.Fields("description").Value	
		strDesc = ""
		If not IsNull(arrDesc) Then
			For Each strItem In arrDesc
				strDesc = strItem
			Next
		End If
	
		'Modify the user account
		Set objUser = GetObject(adoRecord.Fields(0).Value)
		objUser.Put "description", strDesc & " - DISABLED " & Date
		objUser.AccountDisabled = True
		objUser.SetInfo
		On Error GoTo 0
	End If
Loop

wscript.echo "Script finished"

Open in new window

Author

Commented:
thx very much " Scottyworld" please
To disable the pcs I can use the same code
how I can adapt this code
thx
no worries....

Unless you're worried about naming (struser instead of strComputer) then all you need to do is change line 14 of the above code to the following :
 
ldapStr = "<LDAP://" & rootDSE.Get("defaultNamingContext") & ">;(&(objectCategory=computer)(objectClass=computer)(cn=" & strUser & "));ADsPath,description;subtree"

Open in new window

Resolved !!

Please remember to assign points and close questions once you are happy with the answer
Thanks,
Scotty

Author

Commented:
THX IT IS A GOOD SUPPORT

Explore More ContentExplore courses, solutions, and other research materials related to this topic.