A. To delete the accounts listed in the file that I created in the FAQ, "How can I create a file that contains all user profiles that were created before a specific date?" (FAQ), ), I first created a text file that included information in the following format:
<dn of next account to delete>|\[optional info after the pipe\]</dn></dn>
CN=test2,OU=testing,DC=demo,DC=local|6/2/2004 10:55:14 PM
A pipe character (|) must follow the account's distinguished name (DN); the script ignores what follows the pipe.
I then wrote the delusersfromfile.vbs script, which deletes the accounts listed in the file. You can download the script at Code. Save the script as delusersfromfile.vbs. Remember to modify the script to include information specific to your installation.
Dim strFilePath, objFSO, objFilesTarget, sUser, objParent, sLine, aLine, _
' Check that all required arguments have been passed.
If Wscript.Arguments.Count required. For example:" & vbCrLf _
& "cscript delusersfromfile.vbs c:\temp\UserList.txt"
strFilePath = Wscript.Arguments(0)
Const ForReading = 1
Set objFSO = CreateObject("scripting.filesystemobject")
Set objFilesTarget = objFSO.OpenTextFile(strFilePath,ForReading,True)
Do While objFilesTarget.AtEndOfStream True
sLine = objFilesTarget.ReadLine
aLine = split(sline, "|",-1,1)
sDN = aLine(0)
On Error Resume Next
sUser = "LDAP://" & sDN
Set oUser = GetObject(sUser)
Set objParent = GetObject(oUser.parent)
objParent.Delete "User", (oUser.Name)
Set oUser = Nothing
To run delusersfromfile.vbs, at a command prompt enter
cscript delusersfromfile.vbs c:\temp\list.txt
You'll see output on screen that's similar to this:
Copyright (C) Microsoft Corporation 1996-2001. All rights reserved.
After executing delusersfromfile.vbs, you could run a script to verify whether the accounts have been deleted. For example, you could run the listusersolder.vbs script that I discuss in "How can I create a file that contains all user profiles that were created before a specific date?"; the list that the script outputs should be empty of old accounts.