Delete disabled accounts from TXT file - TechRepublic
General discussion
March 24, 2009 at 03:36 AM
shirokit

Delete disabled accounts from TXT file

by shirokit . Updated 17 years, 3 months ago

Hi

I have a problem. I need to provide the guy that handles the inactive accounts with a script to delete disabled accounts out of AD from a txt file.

I have created a script but I can?t seem to get the value pulled trough to delete the accounts

I put in simple wscript.echo commands to help track where the problem lies and I can see that it does not get the value of the user account SAMA name at line 24 even though the first test shows me that strUser variable gets the value from the txt.

Any help will be appreciated. I have provided the script as it is atm

On Error Resume Next

Const ADS_SCOPE_SUBTREE = 2
Const ForReading = 1

Set objFSO = CreateObject(“Scripting.FileSystemObject”)
Set objConnection = CreateObject(“ADODB.Connection”)
Set objCommand = CreateObject(“ADODB.Command”)
objConnection.Provider = “ADsDSOObject”
objConnection.Open “Active Directory Provider”
Set objCommand.ActiveConnection = objConnection
Set objTextFile = objFSO.OpenTextFile (“Users_Disable.txt”, ForReading)

Do Until objTextFile.AtEndOfStream
strUser = objTextFile.Readline

wscript.echo strUser

objCommand.Properties(“Page Size”) = 1000
objCommand.Properties(“Searchscope”) = ADS_SCOPE_SUBTREE

objCommand.CommandText = _
“SELECT distinguishedName FROM ‘LDAP://dc=angloplat,dc=net’ WHERE objectCategory=’user’ ” & _
“AND sAMAccountName=strUser”
Set objRecordSet = objCommand.Execute

objRecordSet.MoveFirst
Do Until objRecordSet.EOF
dim userDN
dim strUserDN
userDN = objRecordSet.Fields(“distinguishedName”).Value
wscript.echo “2”
wscript.echo userDN
‘set objUser = GetObject(“LDAP://” & userDN)
‘objUser.DeleteObject(0)
objRecordSet.MoveNext
Loop
loop

This discussion is locked

All Comments