Last active
June 10, 2020 14:03
-
-
Save XPlantefeve/9b1e987baf1024149edad58bb88490b2 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<#PSScriptInfo | |
.VERSION 1.0 | |
.GUID 021fb1d9-6c04-4bea-983b-92e03d14963d | |
.AUTHOR Xavier Plantefeve | |
.COPYRIGHT 2020 Xavier Plantefeve | |
.TAGS ActiveDirectory,Password | |
.LICENSEURI https://opensource.org/licenses/MIT | |
.PROJECTURI https://gist.github.com/XPlantefeve/9b1e987baf1024149edad58bb88490b2 | |
.EXTERNALMODULEDEPENDENCIES ActiveDirectory | |
#> | |
<# | |
.SYNOPSIS | |
Resets the PasswordLastSet Active Directory attribute of an user | |
.DESCRIPTION | |
The Reset-PwdLastSet cmdlet resets the PasswordLastSet Active Directory attribute | |
of an user to the current date and time. | |
The operator needs to have the relevant rights in Active Directory | |
.EXAMPLE | |
PS C:\> .\Reset-PwdLastSet.ps1 -Name JohnDoe | |
Resets JohnDoe's password date | |
.EXAMPLE | |
PS C:\> Get-ADGroupMember Resetables | .\Reset-PwdLastSet.ps1 -PassTrhu | |
Resets the password date for all members of the Resetables group and outputs | |
the modified user objects | |
.INPUTS | |
string | |
.OUTPUTS | |
aduser | |
.NOTES | |
This script only contains and calls one standalone function that can be copy-pasted elsewhere. | |
#> | |
Param( | |
[parameter(Mandatory, ValueFromPipeline)] | |
[string]$Name, | |
[switch]$PassThru | |
) | |
function Reset-PwdLastSet { | |
<# | |
.SYNOPSIS | |
Resets the PasswordLastSet Active Directory attribute of an user | |
.DESCRIPTION | |
The Reset-PwdLastSet cmdlet resets the PasswordLastSet Active Directory attribute | |
of an user to the current date and time. | |
The operator needs to have the relevant rights in Active Directory | |
.EXAMPLE | |
PS C:\> Reset-PwdLastSet -Name JohnDoe | |
Resets JohnDoe's password date | |
.EXAMPLE | |
PS C:\> Get-ADGroupMember Resetables | Reset-PwdLastSet -PassTrhu | |
Resets the password date for all members of the Resetables group and outputs | |
the modified user objects | |
.INPUTS | |
string | |
.OUTPUTS | |
aduser | |
#> | |
param( | |
[parameter(Mandatory, ValueFromPipeline)] | |
# SamAccountName of the user. Actually accepts identity in the Active Directory | |
# meaning of the term: SamAccountName, DistinguishedName, Guid or SID. AD users | |
# (Get-ADUser) or objects (Get-ADObject) can be piped too. | |
[string]$Name, | |
# If selected, will output AD users with default properties + PasswordLastSet. | |
[switch]$PassThru | |
) | |
process { | |
$Name | | |
Get-ADUser | | |
Set-ADObject -Replace @{PwdLastSet = 0 } -PassThru | | |
Set-ADObject -Replace @{PwdLastSet = -1 } -PassThru:$PassThru | | |
Get-ADUser -Properties PasswordLastSet | |
} | |
} | |
$Name | Reset-PwdLastSet -PassThru:$PassThru |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment