Skip to main content

Posts

Showing posts from June, 2009

Finding Old or Unused Accounts with Powershell

Recently I tried to find accounts that haven't been used in a long time. In order to do this I wrote a powershell script to get the last logon time for all accounts in the domain. The problem is, each domain controller contains a different time for the Last Logon depending on which was used as the logon server. In order to get an accurate time we need to get the last logon from each domain controller for each user. This is NOT a fast process. If there are 500 users and 4 domain controllers that is 2000 requests. On top of that some of the domain controllers might be a different location with a slower WAN link which will make it go even slower.

Note: This script requires Quest Software's Active Directory cmdlets. You can download it from here: http://www.quest.com/powershell/activeroles-server.aspx


Add-PSSnapIn Quest.ActiveRoles.ADManagement -ErrorAction SilentlyContinue
$dcs = Get-QADComputer -ComputerRole DomainController $users = Get-QADUser -SizeLimit 0
#$ErrorActionPreference =…