Amend-pwdLastSet.ps1

something exciting

Some information about the exciting thing

Table of contents generated with markdown-toc


Script

<#
Get-ADUser "ADUserName" -Properties PasswordExpired | Select-Object PasswordExpired

Set-ADUser "ADUserName" -Replace @{pwdLastSet='0'}

$users = Get-ADUser -Filter {name -like '*' } -Properties *
foreach($user in $users){ Set-ADUser -Replace @{pdwLastSet='0' -whatif }
#>

function Get-PasswordLastSetDate {
    [CmdletBinding(SupportsShouldProcess = $false)]
    param (
        [Parameter(Mandatory = $true,
            ValueFromPipeline = $false,
            ValueFromPipelineByPropertyName = $True,
            HelpMessage = "Enter username")]
        [Alias('un')]
        [string[]]$Identity,
        [Parameter(Mandatory = $true,
            ValueFromPipeline = $false,
            ValueFromPipelineByPropertyName = $True,
            HelpMessage = "Enter Domain name")]
        [Alias('dom')]
        [string[]]$Domain
    )

    BEGIN {
    }

    PROCESS {
        foreach ($User in $Identity) {
            $PasswordTest = Get-ADUser -Identity $User -Server "$Domain" -Properties "pwdLastSet" | Select-Object -Property Name, @{name = "pwdLastSet"; expression = { [datetime]::FromFileTime($_.pwdLastSet) } }
            try {
                $Properties = @{
                    "Username"   = $PasswordTest.Name
                    "pwdLastSet" = $PasswordTest.pwdLastSet
                }
            }
            catch {
                $Properties = @{
                    "Username"   = $PasswordTest.Name
                    "pwdLastSet" = $PasswordTest.pwdLastSet
                }
            }
            finally {
                $obj = New-Object -TypeName PSObject -Property $Properties
                Write-Output $obj
            }
        }
    }
    END {

    }

}

function Set-PasswordExpired {
    [CmdletBinding(SupportsShouldProcess = $false)]
    param (
        [Parameter(Mandatory = $true,
            ValueFromPipeline = $false,
            ValueFromPipelineByPropertyName = $True,
            HelpMessage = "Enter Username for account to be expired")]
        [Alias('id')]
        [string[]]$Identity
    )

    BEGIN {
    }

    PROCESS {

        foreach ($User in $Identity) {
            Set-ADUser $User -Replace @{pwdLastSet = '0' }
            $Reset = Get-ADUser $User -Properties PasswordExpired | Select-Object -Property Name, PasswordExpired
            try {
                $Properties = @{
                    "Username"        = $Reset.Name
                    "PasswordExpired" = $Reset.PasswordExpired
                }
            }
            catch {
                $Properties = @{
                    "Username"        = $Reset.Name
                    "PasswordExpired" = $Reset.PasswordExpired
                }
            }
            finally {
                $obj = New-Object -TypeName PSObject -Property $Properties
                Write-Output $obj
            }
        }
    }
    END {

    }
}

Back to Top


Download

Please feel free to copy parts of the script or if you would like to download the entire script, simple click the download button. You can download the complete repository in a zip file by clicking the Download link in the menu bar on the left hand side of the page.


Report Issues

You can report an issue or contribute to this site on GitHub. Simply click the button below and add any relevant notes. I will attempt to respond to all issues as soon as possible.

Issue


Back to Top