Help Fix my PS Script.

This is a Correct Script that sends PSWD expiring Notifications.

$CommandToGetInfoFromAD | ForEach {

$Today = (Get-Date)

$UserName = $_.Name

if (!$_.PasswordExpired -and !$_.PasswordNeverExpires) {

$ExpiryDate = ($_.PasswordLastSet+$maxPasswordAge)

$ExpiryDateForEmail = $ExpiryDate.ToString("dddd, MMMM dd yyyy a\t hh:mm tt")

$DaysLeft = ($ExpiryDate-$Today).days

if ($DaysLeft -lt $DaysBeforeExpiry -and $DaysLeft -gt 0) {

$MailProperties = @{

Attachments = "$jpg"

From = $From

To = $_.EmailAddress

Subject = $MailSubject

SMTPServer = $SMTPServer

}

******************************************************************This is a Script that will check last Logon in AD and send Notification to fill out security questions and Answer. This is not correct. Help me correct it.

$CommandToGetInfoFromAD | ForEach {

$Today = (Get-Date)

$UserName = $_.Name

if (!$_.Get-ADuser -Identity "Username" -Properties "LastLogonDate") {

$LastLogonTimeStamp = $(If($LastLogon -match "12/31/1600")

if ($DaysLeft -lt $DaysBeforeExpiry -and $DaysLeft -gt 0) {

$MailProperties = @{

Attachments = "$jpg"

From = $From

To = $_.EmailAddress

Subject = $MailSubject

SMTPServer = $SMTPServer

There are a lot of examples of how to handle password expiration as pretty much every company needs it. My recommendation is just do a search…

"powershell password expiration reminder"