public/Reset-Passwords.ps1

Function Reset-Passwords {

    [cmdletbinding(SupportsShouldProcess=$True)]
    
    param (

    [Parameter(Mandatory=$true,Position=0)]
    [string]$NewPwd,

    [switch]$RequireChange

    )


    # Get all the users in the OU

    $OU = Select-ADOrganizationalUnit -HideNewOUFeature | Select-Object DistinguishedName -ExpandProperty DistinguishedName
    $Users = Get-ADUser -Filter * -Properties * -SearchBase $OU

    foreach ($U in $Users) {
    
        # Set the users password
        Set-ADAccountPassword -Identity $U.SamAccountName -NewPassword (ConvertTo-SecureString $NewPwd -AsPlainText -Force) -Reset
        # If require change then do so
        if ($RequireChange) {
            Set-ADUser -Identity $U.SamAccountName -ChangePasswordAtLogon $true
        }
    
    Write-Host "$($U.Name)'s password has been updated" -ForegroundColor Green
        
    }
}