Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Jun 25th, 2012  |  syntax: None  |  size: 1.83 KB  |  hits: 19  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
This paste has a previous version, view the difference. Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. #Add the Quest PowerShell snapin
  2. Add-PsSnapIn Quest.ActiveRoles.ADManagement -ErrorAction SilentlyContinue
  3. Get-QADUser -SearchRoot "OU=Windows Standaard,OU=Jalema,DC=jalema,DC=com" -SizeLimit 0  | Select-Object samAccountName,mail,PasswordStatus |
  4. Where-Object {$_.PasswordStatus -ne "Password never expires" -and $_.PasswordStatus -ne "Expired" -and $_.PasswordStatus -ne "User must change password at next logon." -and $_.mail -ne $null} |
  5. ForEach-Object {
  6.   $today = Get-Date
  7.   $logdate = Get-Date -format yyyyMMdd
  8.   $samaccountname = $_.samAccountName
  9.   $mail = $_.mail
  10.   $passwordstatus = $_.PasswordStatus
  11.   $passwordexpiry = $passwordstatus.Replace("Expires at: ","")
  12.   $passwordexpirydate = Get-Date $passwordexpiry
  13.   $daystoexpiry = ($passwordexpirydate - $today).Days
  14.   $smtpserver = "172.16.3.54"
  15.   $attachment = "F:\JSBSB Systeem- & netwerkbeheer\JSBSB000 Algemeen (richtlijnen, werkwijzen)\change password instruction.doc"
  16.   $emailFrom = "systeembeheer@jalema.com"
  17.   $body = "Please change your password to prevent loss of access to your *Jalema* systems`n`n"
  18.   $body += "If you are unable to change your password, please contact the help desk at ext 221 / 225 or +31-77-4767621"
  19.   if ($daystoexpiry -lt 9 ) {
  20.     $emailTo = "$mail"
  21.     $subject = "Your Network password will expire in $daystoexpiry day(s) please change your password."    
  22.     Send-MailMessage -To $emailTo -From $emailFrom -Subject $subject -Body $body -Attachments $attachment -SmtpServer $smtpserver
  23.     Write-Host "Email was sent to $mail on $today"
  24.     Add-Content c:\logs\maillog$logdate.txt  "Email was sent to $mail on $today"
  25.   }
  26. }
  27. Send-MailMessage -To "systeembeheer@jalema.com" -From "systeembeheer@jalema.com" -Subject "Password change log for $today" -Body "This is the log from $today" -Attachments "c:\logs\maillog$logdate.txt" -SmtpServer $smtpserver