Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Name: Get-ExpiringPasswords.ps1
- # Author: James Schlackman
- # Last Modified: Sep 20 2017
- #
- # Checks all enables users in a given OU to see if their password is going to expire during
- # a given date range. Exports a listof those affected.
- # Useful for finding out who to remind about changing their password before long vacations.
- #
- Import-Module ActiveDirectory
- $maxPwdAge = 180
- $checkOU = "OU=People,DC=contoso,DC=com"
- $startDate = (Get-Date 2017-06-21)
- $endDate = (Get-Date 2017-08-30)
- Get-ADUser -SearchBase $checkOU -SearchScope OneLevel -Filter {(Enabled -eq $true ) -and (passwordLastSet -gt 0)} -Properties passwordLastSet,mail |`
- Select GivenName,Surname,mail,passwordLastSet,@{Name="Expires";Expression={($_.passwordLastSet).AddDays($maxPwdAge)}} |`
- Where-Object {($_.Expires -gt $startdate) -and ($_.Expires -lt $enddate)} |`
- Export-Csv -NoTypeInformation -Path ((Get-Date).ToString("yyMMdd") + " Expiring Passwords.csv")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement