Skip to content

Commit 86653dd

Browse files
committed
Update Microsoft Active Directory.ps1
- Preserve ChangePasswordAtNextLogon flag when setting password. But still allow it to be overridden in mapping
1 parent dd0192d commit 86653dd

1 file changed

Lines changed: 15 additions & 0 deletions

File tree

Microsoft Active Directory.ps1

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1574,7 +1574,22 @@ function Set-ADObject-ADSI {
15741574

15751575
'AccountPassword' {
15761576
try {
1577+
# Retrieve current ChangePasswordAtNextLogon
1578+
if ($dirent.Properties["pwdLastSet"][0] -is [System.__ComObject]) {
1579+
$ChangePassword = ConvertFrom-ADLargeInteger $dirent.Properties["pwdLastSet"][0]
1580+
}
1581+
else {
1582+
$ChangePassword = $dirent.Properties["pwdLastSet"][0]
1583+
}
1584+
1585+
# Update Password
15771586
$dirent.Invoke('SetPassword', $Properties[$p]) >$null
1587+
1588+
# Preserve ChanagePasswordAtNextLogon Flag
1589+
$val = if ($ChangePassword -eq 0) { 0 } else { -1 }
1590+
1591+
$dirent.Properties['pwdLastSet'].Clear()
1592+
$dirent.Properties['pwdLastSet'].Add((ConvertTo-ADLargeInteger $val)) >$null
15781593
} catch {
15791594
Get-ADSIError
15801595
throw $_

0 commit comments

Comments
 (0)