windows:scripting:password_expire

no way to compare when less than two revisions

Differences

This shows you the differences between two versions of the page.


windows:scripting:password_expire [2020/05/20 12:47] (current) – created - external edit 127.0.0.1
Line 1: Line 1:
 +====== Get AD password expire time ======
 +<code powershell>
 +$users = Get-ADUser -filter {Enabled -eq $True -and PasswordNeverExpires -eq $False} –Properties "DisplayName", "msDS-UserPasswordExpiryTimeComputed", "mail" | Select-Object -Property "Displayname","mail",@{Name="ExpiryDate";Expression={[datetime]::FromFileTime($_."msDS-UserPasswordExpiryTimeComputed")}}
 +foreach ($user in $users) {
 +    if (($user.ExpiryDate -ne $null) -and ($user.DisplayName -ne $null) -and ($user.mail -ne $null)) {
 +        $diff = New-Timespan -End $user.ExpiryDate.ToString("yyyy-MM-dd") -Start (Get-Date).ToString("yyyy-MM-dd")
 +        if (($diff.days -le 15) -and ($diff.days -gt 0)) {
 +            Send-MailMessage -To $user.mail -From "it@example.com" -cc "logs@example.com" -Subject "Password expires soon" -Body "info on how to change password" -SmtpServer "10.134.10.195" -Port 26
 +        }
 +        if ($diff.days -eq 0) {
 +            Send-MailMessage -To $user.mail -From "it@example.com" -cc "logs@example.com" -Subject "Password expires today" -Body "info on how to change password" -SmtpServer "10.134.10.195" -Port 26
 +        }
 +        if ($diff.days -le 0) {
 +            Send-MailMessage -To $user.mail -From "it@example.com" -cc "logs@example.com" -Subject "Password expired" -Body "info on how to change password" -SmtpServer "10.134.10.195" -Port 26
 +        }
 +    }
 +}
 +</code>
  
 +Create task schedule and run script daily
  • windows/scripting/password_expire.txt
  • Last modified: 2020/05/20 12:47
  • by 127.0.0.1