Windows OS Hub
  • Windows
    • Windows 11
    • Windows Server 2022
    • Windows 10
    • Windows Server 2019
    • Windows Server 2016
  • Microsoft
    • Active Directory (AD DS)
    • Group Policies (GPOs)
    • Exchange Server
    • Azure and Microsoft 365
    • Microsoft Office
  • Virtualization
    • VMware
    • Hyper-V
  • PowerShell
  • Linux
  • Home
  • About

Windows OS Hub

  • Windows
    • Windows 11
    • Windows Server 2022
    • Windows 10
    • Windows Server 2019
    • Windows Server 2016
  • Microsoft
    • Active Directory (AD DS)
    • Group Policies (GPOs)
    • Exchange Server
    • Azure and Microsoft 365
    • Microsoft Office
  • Virtualization
    • VMware
    • Hyper-V
  • PowerShell
  • Linux

 Windows OS Hub / Active Directory / Extend an Expired User Password in Active Directory

December 23, 2024 Active DirectoryPowerShell

Extend an Expired User Password in Active Directory

The password policy, which is enabled by default in Active Directory, sets a maximum age for a user’s password. If the password age exceeds this value, it is considered expired, and the user must change it at the next login.

The administrator can extend the password expiration date when a domain user cannot change their expired password (for example, when a user connects to a corporate network via VPN or RDS) without enabling the Password never expires option for the account.

Use PowerShell to check the expiration date of the user’s password in AD:

Get-ADUser -Identity e.herrmann -Properties msDS-UserPasswordExpiryTimeComputed, PasswordLastSet, PasswordNeverExpires, PasswordExpired |Select-Object -Property Name,PasswordLastSet, PasswordNeverExpires, PasswordExpired,@{Name="ExpiryDate";Expression={[datetime]::FromFileTime($_."msDS-UserPasswordExpiryTimeComputed")}}

PowerShell: find out if AD user password expired

In this case, the user’s password has expired( PasswordExpired=True ). The password expiration date is stored in a computed attribute named msDS-UserPasswordExpiryTimeComputed. This attribute’s value is calculated based on the value of the pwdLastSet parameter and the resulting password policy that applies to the user.

Get-ADUser e.herrmann -Properties pwdLastSet | select SamAccountName,@{Name="pwdLastSet";Expression={[datetime]::FromFileTime($_.pwdLastSet)}}

powershell: get ad user password last set

The pwdLastSet attribute contains the date in millisecond format (Windows NT time). However, it can take one of the following special values:

  • 0 – reset the pwdlastset value (means the password was never set)
  • -1 – reset the user password change date to the current time

To change the value of the user attribute, use the Set-ADUser PowerShell cmdlet. First, you have to set 0 and then -1.

Set-ADUser e.herrmann -Replace @{pwdLastSet='0'}
Set-ADUser e.herrmann -Replace @{pwdLastSet='-1'}

Now let’s check the user’s password change and expiration dates. The password change date has been changed to the current date, and the user’s password expiration date has been extended.

Extend expired AD user password using PowerShell:

It is impossible to set a specific password change date in AD.

This method of extending user passwords can also be used if you plan to enable a domain password expiration policy after user passwords have been set to never expire or the PasswordNeverExpires option has been enabled. Enabling this policy will force all users to change their passwords simultaneously, potentially disrupting work processes Before applying this policy, extend the password expiration date for all users as instructed.

2 comments
10
Facebook Twitter Google + Pinterest
previous post
Fix: Windows Update Tab (Button) is Missing from Settings
next post
Hardware Graphics Acceleration Causes Visual Glitches in Microsoft Office Apps

Related Reading

Configure NTP Time Source for Active Directory Domain

May 6, 2025

View Windows Update History with PowerShell (CMD)

April 30, 2025

Uninstalling Windows Updates via CMD/PowerShell

April 18, 2025

Allowing Ping (ICMP Echo) Responses in Windows Firewall

April 15, 2025

How to Pause (Delay) Update Installation on Windows...

April 11, 2025

2 comments

Martin December 26, 2024 - 12:28 pm

#for one user
import-module activedirectory

#Change my.user with the target user account.
$username = “user.name”

#This command will get the current PwdLastSet value.

$User = Get-ADUser $username -properties pwdlastset
#Display the current password last set date (convert date to human readable):
[datetime]::fromFileTime($user.pwdlastset)

#Change the user’s pwdlastset attribute to 0
$User.pwdlastset = 0

#Apply the changes against the object
Set-ADUser -Instance $User

#Change the user’s pwdlastset attribute to -1
$user.pwdlastset = -1

#Apply the changes against the object
Set-ADUser -instance $User

#Read again the value from AD
$User = Get-ADUser $username -properties pwdlastset

#Current password last set date, it should be displaying today (convert date to human readable):
[datetime]::fromFileTime($user.pwdlastset)

Reply
Martin December 26, 2024 - 12:30 pm

##for all in OU
Import-Module ActiveDirectory
$ADUserParams=@{
‘Searchbase’ = ‘OU=Users,DC=domain,DC=local’
‘Filter’ = ‘*’
‘Properties’ = ‘cn’,’sn’,’givenname’,’displayName’,’mail’,’description’,’UserPrincipalName’, ’employeeNumber’, ‘profilepath’, ‘title’
}

$ADUsers = Get-ADUser @ADUserParams
ForEach ($ADUser in $ADUsers) {

$ADUser = Get-ADUser $ADUser -properties pwdlastset
$ADUser.pwdlastset = 0
Set-ADUser -Instance $ADUser
$ADUser.pwdlastset = -1
Set-ADUser -instance $ADUser

Get-ADUser -Identity $ADUser -Properties PwdLastSet | Select-Object -Property “Name”, @{n=”PwdLastSet”;e={[datetime]::FromFileTime($_.”PwdLastSet”)}}
}

Reply

Leave a Comment Cancel Reply

join us telegram channel https://t.me/woshub
Join WindowsHub Telegram channel to get the latest updates!

Categories

  • Active Directory
  • Group Policies
  • Exchange Server
  • Microsoft 365
  • Azure
  • Windows 11
  • Windows 10
  • Windows Server 2022
  • Windows Server 2019
  • Windows Server 2016
  • PowerShell
  • VMware
  • Hyper-V
  • Linux
  • MS Office

Recent Posts

  • Cannot Install Network Adapter Drivers on Windows Server

    April 29, 2025
  • Change BIOS from Legacy to UEFI without Reinstalling Windows

    April 21, 2025
  • How to Prefer IPv4 over IPv6 in Windows Networks

    April 9, 2025
  • Load Drivers from WinPE or Recovery CMD

    March 26, 2025
  • How to Block Common (Weak) Passwords in Active Directory

    March 25, 2025
  • Fix: The referenced assembly could not be found error (0x80073701) on Windows

    March 17, 2025
  • Exclude a Specific User or Computer from Group Policy

    March 12, 2025
  • AD Domain Join: Computer Account Re-use Blocked

    March 11, 2025
  • How to Write Logs to the Windows Event Viewer from PowerShell/CMD

    March 3, 2025
  • How to Hide (Block) a Specific Windows Update

    February 25, 2025

Follow us

  • Facebook
  • Twitter
  • Telegram
Popular Posts
  • Allow Non-admin Users RDP Access to Windows Server
  • How to Disable NTLM Authentication in Windows Domain
  • Configure Windows LAPS (Local Administrator Passwords Solution) in AD
  • Refresh AD Groups Membership without Reboot/Logoff
  • Enable Single Sign-On (SSO) Authentication on RDS Windows Server
  • How to Add, Set, Delete, or Import Registry Keys via GPO
  • How to Reset Active Directory Domain Admin Password
Footer Logo

@2014 - 2024 - Windows OS Hub. All about operating systems for sysadmins


Back To Top