Friday, October 4, 2013

powershell script to find the user account lockedout status

import-module ActiveDirectory

#get list of accounts to check
$systemAccounts = Get-Content "c:\Scripts\SystemAccounts.txt"


#check if any of these accounts are locked
$lockedAccounts = Search-ADAccount –LockedOut | Where {$systemAccounts -contains $_.Name} | echo Name

#not yet tested this -draft

Last password change info - Powershell

Last password changed

PS #> $searcher=New-Object DirectoryServices.DirectorySearcher
PS #> $searcher.Filter="(&(samaccountname=user1))"
PS #> $results=$searcher.findone()
PS #> [datetime]::fromfiletime($results.properties.pwdlastset[0])