Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@Windos
Created January 25, 2018 10:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Windos/17ce81e36cc635638f30e5cb79791051 to your computer and use it in GitHub Desktop.
Save Windos/17ce81e36cc635638f30e5cb79791051 to your computer and use it in GitHub Desktop.
Pester people with toasts when their password is close to expiring
$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