Pester people with toasts when their password is close to expiring
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
$JobBlock = { | |
$ExpiryTime = Get-ADUser $env:USERNAME -Properties 'msDS-UserPasswordExpiryTimeComputed' | |
$Expiry = [datetime]::FromFileTime($ExpiryTime.'msDS-UserPasswordExpiryTimeComputed') | |
$TimeToGo = New-TimeSpan -Start (Get-Date) -End $Expiry | |
if ($TimeToGo -le 3) { | |
if ($TimeToGo.Days -gt 0) { | |
$Count = $TimeToGo.Days | |
$Unit = 'Days' | |
} else { | |
$Count = $TimeToGo.Hours | |
$Unit = 'Hours' | |
} | |
New-BurntToastNotification -Sound Alarm10 ` | |
-Text 'Your password is close to expiring!', | |
"Please change your password soon, it will expire in $Count $Unit.", | |
'You can change it any time by pressing CTRL + ALT + DEL and choosing "Change a password."' | |
} | |
} | |
$JobTrigger = New-JobTrigger -Once ` | |
-At "01:00" ` | |
-RepeatIndefinitely ` | |
-RepetitionInterval (New-TimeSpan -Minutes 90) | |
$JobOptions = New-ScheduledJobOption -RequireNetwork | |
Register-ScheduledJob -Name 'Password Expiry Reminder' ` | |
-ScriptBlock $JobBlock ` | |
-Trigger $JobTrigger ` | |
-ScheduledJobOption $JobOptions | |
$Principal = New-ScheduledTaskPrincipal -LogonType Interactive -UserId $ENV:USERNAME | |
Set-ScheduledTask -Principal $Principal ` | |
-TaskPath '\Microsoft\Windows\PowerShell\ScheduledJobs\' ` | |
-TaskName 'Password Expiry Reminder' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment