Deleting users after they leave

G

Guest

is there a way or a script that deletes users in AD after they havent logged on for a certain amount of time.
 
R

Ron Oglesby [MVP]

Different ways to do this but the easiest is most likely VB.

Combine the following two scripts with some logic for the number of days you
want to use and you are golden, first script is from

http://www.myitforum.com/articles/11/view.asp?id=204

Each script prompts for a specific domain and user account and then polls
the ADSI to retrieve and display the information.

Copy and paste the following script (between the lines) into Notepad, making
sure to have Word Wrap disabled, then save it with a .vbs extension.

Last Login:
==================================
On Error Resume Next
Dim User
Dim UserName
Dim UserDomain
UserDomain = InputBox("Enter the name of the domain:")
UserName = InputBox("Enter the name of the user:")
Set User = GetObject("WinNT://" & UserDomain & "/" & UserName & ",user")
MsgBox "The last time " & UserName & " logged on was: " & vbCRLf & vbCRLf &
User.LastLogin
==================================

Last Logoff:
==================================
On Error Resume Next
Dim User
Dim UserName
Dim UserDomain
UserDomain = InputBox("Enter the name of the domain:")
UserName = InputBox("Enter the name of the user:")
Set User = GetObject("WinNT://" & UserDomain & "/" & UserName & ",user")
MsgBox User.LastLogoff
==================================

Now this looks for input for the Username and domain. But you get the idea.
Instead of prompting for the user name use a windows script to pull them
(create a collection) then do a for each in the collection with some logic
against the User.LastLogin.

Then in the same script if the last login is beyond your specified time
period use the below script (from the Windows 2000 scripting guide) to
delete that user. Just pump in the variables from earlier in the script.

Description
Deletes the Active Directory user account named AckermanPilar.

Script Code

Set objOU = GetObject("LDAP://ou=Management,dc=NA,dc=fabrikam,dc=com")

objOU.MoveHere _
"LDAP://cn=AckermanPilar,ou=Management,dc=fabrikam,dc=com", _
vbNullString
If you hanvet done any VBS before go get the Windows 2000 Admin scripting
guide. It will walk you through the basics, From there you can find code
snips like these and piece together what you need to do almost anything.


--
Ron Oglesby
Microsoft MVP - Terminal Services


kidem said:
is there a way or a script that deletes users in AD after they havent
logged on for a certain amount of time.
 
A

Andreas

You might be interested in AdmWin / SetupBatcher. http://www.admwin.com.
Search the manual for "Manage accounts by WhenChanged, WhenCreated and
LastLogon".

Regards
Andreas

kidem said:
is there a way or a script that deletes users in AD after they havent
logged on for a certain amount of time.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top