Created
October 31, 2011 15:28
-
-
Save jpogran/1327754 to your computer and use it in GitHub Desktop.
Users Whose Password About to Expire
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ##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