Skip to content
ShabazTech

Notes of an IT Pro

ShabazTech

Notes of an IT Pro

  • Microsoft Azure
    • Compute
    • Governance
    • Identity
    • Networking
    • Security
    • Storage
  • Microsoft Entra ID
    • Identity
      • Application Management
      • Governance
    • Security
      • Authentication
      • Conditional Access
    • Global Secure Access
      • Internet Access
      • Private Access
  • Microsoft Intune
    • Apps
      • Microsoft365 Apps For Enterprise
    • Devices
      • Windows Clients
    • Monitoring
    • Security
  • Microsoft 365
    • Defender XDR
    • Purview
  • Microsoft OnPrem
    • AD DS
    • Failover Clustering
    • Hyper-V
    • Powershell
    • SQL Server
      • SQL Server 2008R2
      • SQL Server 2012
      • SQL Server 2016
    • System Center Configuration Manager
      • SCCM 2012R2
    • Windows Clients
    • Windows Server
      • Windows Server 2008R2
      • Windows Server 2012
      • Windows Server 2012R2
      • Windows Server 2016
  • Citrix
    • XenApp 6.5
    • XenApp and XenDesktop 7.6 LTSR
    • XenApp and Xendesktop 7.15 LTSR
  • About The Author
  • Microsoft Azure
    • Compute
    • Governance
    • Identity
    • Networking
    • Security
    • Storage
  • Microsoft Entra ID
    • Identity
      • Application Management
      • Governance
    • Security
      • Authentication
      • Conditional Access
    • Global Secure Access
      • Internet Access
      • Private Access
  • Microsoft Intune
    • Apps
      • Microsoft365 Apps For Enterprise
    • Devices
      • Windows Clients
    • Monitoring
    • Security
  • Microsoft 365
    • Defender XDR
    • Purview
  • Microsoft OnPrem
    • AD DS
    • Failover Clustering
    • Hyper-V
    • Powershell
    • SQL Server
      • SQL Server 2008R2
      • SQL Server 2012
      • SQL Server 2016
    • System Center Configuration Manager
      • SCCM 2012R2
    • Windows Clients
    • Windows Server
      • Windows Server 2008R2
      • Windows Server 2012
      • Windows Server 2012R2
      • Windows Server 2016
  • Citrix
    • XenApp 6.5
    • XenApp and XenDesktop 7.6 LTSR
    • XenApp and Xendesktop 7.15 LTSR
  • About The Author
Close

Search

Subscribe
Active DirectoryMicrosoftPowershellWindows ClientsWindows ServerWindows Server 2008R2

Windows 7 Password Expiry Email Notification

By Shabaz
April 6, 2014 4 Min Read
2
Updated on March 30, 2016



In Windows XP, and Windows Server 2003, you would get a notification at logon when (by default) 14 days remained until your Active Directory user’s password expired. In Windows 7 and Windows Server 2008 R2, Microsoft has changed this feature. Now you don’t get this notification at logon, but rather after you have logged on. And the notification is less intrusive, as you only see it for a few seconds in the system tray, as a balloon notification.

Users obviously easily miss those, and the result is that you are left with users whos passwords aren’t changed until they have actually expired. When the users’ password expire, they will loose connection to exchange servers, and other servers that are dependent on their active directory credentials. Which again will result in a number of support calls, where users might think that something is wrong with their machine, since they are not able to, for example, send and receive e-mails.

The obvious solution to this problem is to notify the users in another manner than the built-in balloon notification. But first let’s look at the difference between XP and Windows 7, then where you can define how many days before password expiration users should be notified, and finally how to resolve the issue, by sending the users an e-mail notification instead of just relying on the balloon notification in the system tray.

1. Difference between Windows 7 and Windows XP

In Windows XP, users were notified at logon, (by default) 14 days prior to their password expired, and the notification would be repeated every day, until their password expired.
xp

In Windows 7, users are notified by a notification balloon in the system tray, (by default) 5 days prior to their password expires, and the notification is repeated every day until their password expires.
passexpiry

2. Group Policy setting to define number of days

The Group Policy setting to define number of days before password expiration, the users should start receiving notification is found in the following location

Computer Configuration\Policies\Windows Settings\Security Settings\Local Policies\Security Options\Interactive logon: Prompt user to change password before expiration

 

In a domain environment, the policy setting is by default Not Defined
noti1

But if you check the Local Security Policy of a Windows 7 or Server 2008 R2 machine, you will see that the policy setting is by default defined as 5 days in those two operating systems.
noti2

3. Send notification by E-mail

Like I have explained earlier, users usually miss the balloon notification they receive in the system tray, and that results in quite a few support calls. So one should rather use other manners to notify users that their Windows password is about to expire, and they should change it as soon as possible. The following Script will notify the users when 7, 3, 2, 1 days remain until their password expires by e-mail.

import-module ActiveDirectory;
$maxPasswordAgeTimeSpan = (Get-ADDefaultDomainPasswordPolicy).MaxPasswordAge
get-aduser -searchbase “ou=user accounts,dc=contoso,dc=com” -filter * -searchscope 1 -properties PasswordLastSet, PasswordExpired, PasswordNeverExpires, EmailAddress, displayName | foreach {

$today=get-date
$UserName=$_.displayName
$Email=$_.EmailAddress

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

$ExpiryDate=$_.PasswordLastSet + $maxPasswordAgeTimeSpan
$DaysLeft=($ExpiryDate-$today).days

if ($DaysLeft -lt 4 -and $DaysLeft -gt 0 -or $DaysLeft -eq 7){

$WarnMsg = “
<p style=’font-family:calibri’>Hello $UserName,</p>
<p style=’font-family:calibri’>Your Windows password is about to expire in $DaysLeft day(s), it is recommended that you change it before it expires. </p>

<p style=’font-family:calibri’>The requirements for new password are as following:</p>
<ul style=’font-family:calibri’>
<li>Minimum Password Length must be 7 characters</li>
<li>Requirement x</li>
<li>Requirement y</li>
<li>Requirement z</li>
</ul>
<p style=’font-family:calibri’></p>
<p style=’font-family:calibri’>Best Regards<br>
IT Helpdesk</p>
“
ForEach ($email in $_.EmailAddress) {
send-mailmessage -to $email -from helpdesk@contoso.com -Subject “Passord Expiry Notification: Your Windows password is about to expire in $DaysLeft day(s)” -body $WarnMsg -smtpserver 192.168.0.25 -BodyAsHtml -Encoding ([System.Text.Encoding]::UTF8) }

}
}
}

Obviously replace any values that do not correspond to your environment.

In the body of the message you can also link to a web page where you can give instructions on how users can reset their password, or who they should talk to if they are not able to do it themselves. When run as a scheduled task, this script can be very useful, as it will reduce the number of support calls you might get due to expired passwords.

Since AD module for Powershell is being imported at the start of the script, you obviously need to either run the script from a Domain Controller, or from a machine where AD module for Powershell has been installed.
rsatpsmodule

If you  are going to schedule the script to run on a Domain Controller, you can use the following command to create the scheduled task

schtasks /CREATE /RU SYSTEM /SC DAILY /TN EmailNotification /TR “powershell.exe -ExecutionPolicy Bypass c:\scripts\emailnotification.ps1 -path C:\scripts\” /ST 05:00:00

This command will create a scheduled task named EmailNotification, and run it daily at 05:00:00. The scheduled task will be ran under the SYSTEM context.

Tags:

Active DirectoryMicrosoftPowershellServer 2008R2Windows ClientsWindows Server
Author

Shabaz

Follow Me
Other Articles
Previous

Installing Failover Clustering on Server 2012

Next

Installing Veritas Storage Foundation on Server 2008 R2

2 Comments
  1. Luca says:
    September 26, 2014 at 05:16

    I don’t know why Microsoft changed it from the way it was in Windows XP, but thanks for the script. I was looking for a way to notify people and this is perfect.

  2. Jyrki says:
    October 11, 2014 at 14:31

    Fantastic script. Thanks!

Comments are closed.

Archives

Tags

Active Directory Citrix Failover Clustering Microsoft Powershell SCCM SCCM 2012R2 Server 2008R2 Server 2012 Server 2012R2 Server 2016 SQL Server Symantec VSF Test Labs Windows Clients Windows Server XenDesktop 7.6 LTSR Xendesktop 7.15 LTSR

Popular Posts

  • How to check if a machine is physical or virtual
  • Exporting multivalued attributes with Export-CSV cmdlet
  • Installing Remote Desktop License Server on Windows…
  • Configuring Remote Desktop Services Profile settings…
  • Installing Citrix XenApp and XenDesktop 7.15 LTSR
  • Enabling LDAPS with certificate from a 3rd party CA
  • Assigning ownership of files and folders with Takeown.exe
  • Retrieving User properties from Active Directory
  • SCCM 2012 R2 Client Installation
  • Citrix XenApp 6.5 Architectural Components
© 2014- 2026 — ShabazTech. All rights reserved.