Help Fix my PS Script.

Welcome Forums General PowerShell Q&A Help Fix my PS Script.

This topic contains 1 reply, has 2 voices, and was last updated by

 
Participant
3 weeks, 3 days ago.

  • Author
    Posts
  • #112645

    Participant
    Points: 0
    Rank: Member

    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
    
  • #112744

    Participant
    Points: 0
    Rank: Member

    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"

You must be logged in to reply to this topic.