Advertisement
Guest User

Untitled

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