This is quiet a bit simplier if you dont mind installing the FREE Quest CMDLets from www.quest.com/powershell.
NOTE: removed -whatif to "REALLY" disable users.
Main Topics
Browse All TopicsIs there a way to automatically (through GPO) disable user accounts on Windows 2003 after 30 days of non-use?
This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.
Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.
If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.
Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.
Access the answers to your technology questions today.
30-day free trial. Register in 60 seconds.
Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Try it out and discover for yourself.
30-day free trial. Register in 60 seconds.
Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.
This is quiet a bit simplier if you dont mind installing the FREE Quest CMDLets from www.quest.com/powershell.
NOTE: removed -whatif to "REALLY" disable users.
Business Accounts
Answer for Membership
by: jss1199Posted on 2008-07-01 at 16:10:01ID: 21912330
This is a bit more difficult to do with Windows 2003 domain controllers since they do not replicate the last logon timestamp. This cannot be done via GPO, but you could use the attached powershell script.
. Using this attribute introduces a delay in determining inactive accounts and therefore may not meet some companies' requirements. If you do not have to disable AT 30 days, I recommend disabling at 45 days so that you are confident that the lastlogonTimeStamp has been replicated.
***Note***
The lastLogonTimeStamp attribute in Active Directory (Windows 2003) is used to determine when a user last logged in. This is the easiest way to detect stale accounts. However, this attribute is only replicated every 10 to 14 days, based on an interval that is randomly calculated using the domain attribute msDS-LogonTimeSyncInterval
***Note***
The parameters for this powershell script are:
· $Subtree: the DN of the container under which you want to look for inactive accounts
· $NbDays: the maximum number of days of inactivity allowed. This script disables all users who have not logged on for longer that the number of days specified.
This filter requests for all the accounts that meet the following conditions:
· Are of object class user,
· Are enabled,
· Have a lastLogonTimeStamp attribute set to a date that is greater than $lastLogonIntervalLimit which is equal to (current-date - $NbDays).
This powershell script was originally posted by Bahram Rushenas on his blog and has been used by me ever since...
Select allOpen in new window