Skip to content

Instantly share code, notes, and snippets.

@jpogran
Created October 31, 2011 15:28
Show Gist options
  • Select an option

  • Save jpogran/1327754 to your computer and use it in GitHub Desktop.

Select an option

Save jpogran/1327754 to your computer and use it in GitHub Desktop.
Users Whose Password About to Expire
##get the Domain Policy for the maximum password age
$dom = [System.DirectoryServices.ActiveDirectory.Domain]::GetCurrentDomain()
$root = $dom.GetDirectoryEntry()
## get the account policy
$search = [System.DirectoryServices.DirectorySearcher]$root
$search.Filter = "(objectclass=domainDNS)"
$result = $search.FindOne()
## maximum password age
$t = New-Object System.TimeSpan([System.Math]::ABS($result.properties["maxpwdage"][0]))
##want all accounts where password will expire in next 7 days
##password was set (max password age) - 7 days ago
$d = ($t.Days)* -1 ## max password age days ago
$d1 = $d +7 ## 7 days on from max password age
Get-QADUser -IncludeAllProperties | Where {($_.PwdLastSet -gt (Get-Date).AddDays($d)) -and ($_.PwdLastSet -lt (Get-Date).AddDays($d1)) }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment