By David Wiseman (Administrator)Created 04 Mar 2008
My Rating:
Vote
Rating:
Not Rated
Views:1967
Downloads:71

Search for All Users by the Date Their Account was Last Modified

Language:  PowerShell

Compatibility

Windows XP Yes Windows 2003 Yes
Windows 2000 No Windows NT No
Vista Unknown Windows 2008 Unknown
Description

Sample script that searches Active Directory for all user accounts modified on October 1, 2007 or later. The whenChanged attribute is replicated to the Global Catalog. This means you can connect to a Global Catalog server and search across the forest for users by the date their account was last modified.

Code

Line Numbers: On  Off      Plain Text
$strFilter = "(&(objectCategory=User)(whenChanged=20071001000000.0Z))"

$objDomain = New-Object System.DirectoryServices.DirectoryEntry

$objSearcher = New-Object System.DirectoryServices.DirectorySearcher
$objSearcher.SearchRoot = $objDomain
$objSearcher.PageSize = 1000
$objSearcher.Filter = $strFilter

$colProplist = "name"
foreach ($i in $colPropList){$objSearcher.PropertiesToLoad.Add($i)}

$colResults = $objSearcher.FindAll()

foreach ($objResult in $colResults)
    {$objItem = $objResult.Properties; $objItem.name}

 


Got a useful script? Click here to upload!


 

  Post Comment
Order By:  
User Comments
      
Be the first to post a comment!