Last active
September 28, 2017 16:02
-
-
Save jschlackman/a4ed1c4c8e3fe76f5e3bfdf8d796c7a4 to your computer and use it in GitHub Desktop.
This file contains 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
# Name: Get-ExpiringPasswords.ps1 | |
# Author: James Schlackman | |
# Last Modified: Sep 28 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 list of 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 ("Expiring Passwords " + (Get-Date).ToString("yyMMdd") + ".csv") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment