Public/Set-Password.ps1
function Set-Password { <# .SYNOPSIS -Taylor Lee Modified 05172019 .DESCRIPTION Sets a Active Directory Password and provides an option to require a password change on login .NOTES Requires the Active Directory Module .EXAMPLE Specifies the username being set and then prompts for a password. Set-Password -username domain\username #> [CmdletBinding()] Param ( [Parameter(Mandatory = $true)] [ValidateScript( { if ($_ -notlike "*\*") { throw "Username must be in the following format Domain\Username" } else { $true } })] $Username, [Parameter(Mandatory = $true)][SecureString]$Password ) Import-Module ActiveDirectory Set-ADAccountPassword -identity $username -Reset -NewPassword $Password $Prompt = Read-Host "Require a Password Change? Type Yes or No." if ($Prompt -eq 'Yes') { Set-ADUser -Identity $Username -ChangePasswordAtLogon $true } else { Write-Host "You specified no" -ForegroundColor Yellow } } |