
Untitled
By: a guest on
Jun 25th, 2012 | syntax:
None | size: 1.83 KB | hits: 19 | expires: Never
#Add the Quest PowerShell snapin
Add-PsSnapIn Quest.ActiveRoles.ADManagement -ErrorAction SilentlyContinue
Get-QADUser -SearchRoot "OU=Windows Standaard,OU=Jalema,DC=jalema,DC=com" -SizeLimit 0 | Select-Object samAccountName,mail,PasswordStatus |
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} |
ForEach-Object {
$today = Get-Date
$logdate = Get-Date -format yyyyMMdd
$samaccountname = $_.samAccountName
$mail = $_.mail
$passwordstatus = $_.PasswordStatus
$passwordexpiry = $passwordstatus.Replace("Expires at: ","")
$passwordexpirydate = Get-Date $passwordexpiry
$daystoexpiry = ($passwordexpirydate - $today).Days
$smtpserver = "172.16.3.54"
$attachment = "F:\JSBSB Systeem- & netwerkbeheer\JSBSB000 Algemeen (richtlijnen, werkwijzen)\change password instruction.doc"
$emailFrom = "systeembeheer@jalema.com"
$body = "Please change your password to prevent loss of access to your *Jalema* systems`n`n"
$body += "If you are unable to change your password, please contact the help desk at ext 221 / 225 or +31-77-4767621"
if ($daystoexpiry -lt 9 ) {
$emailTo = "$mail"
$subject = "Your Network password will expire in $daystoexpiry day(s) please change your password."
Send-MailMessage -To $emailTo -From $emailFrom -Subject $subject -Body $body -Attachments $attachment -SmtpServer $smtpserver
Write-Host "Email was sent to $mail on $today"
Add-Content c:\logs\maillog$logdate.txt "Email was sent to $mail on $today"
}
}
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