Posted On June 4, 2020

PowerShell: Reset Password for All Users inside an OU

kimconnect 0 comments
blog.KimConnect.com >> Codes >> PowerShell: Reset Password for All Users inside an OU
$ouName="Funky Dudes"
$ouPath = "ou=$ouName,dc=intranet,dc=baam,dc=com"
$plaintextPassword='WHATPASSWORD?'

$users=Get-ADUser -Filter * -SearchBase $ouPath | Select-object Name,UserPrincipalName,DistinguishedName
foreach ($user in $users){
    write-host "Resetting '$($user.Name)' password to '$plaintextPassword'";
    pause;
    try{
        Set-ADAccountPassword -Identity $user.DistinguishedName -Reset -NewPassword (ConvertTo-SecureString -AsPlainText $plaintextPassword -Force);
        write-host "'$($user.DistinguishedName)' password has been reset successfully";
        }
    catch{
        write-host 'failed.'
        }
}

Leave a Reply

Your email address will not be published. Required fields are marked *

Related Post

PowerShell: Grant SMB Access

# grantSmbAccess.ps1 $computername='fileserver' $shareName='TEST' $account='domain\groupOrUsername' $accessType='read' # also change or full invoke-command -computername $computername -scriptblock{…

Basic CSS: Use RGB to Mix Colors

<style>.red-text {color: #000000;}.orchid-text {color: #000000;}.sienna-text {color: #000000;}.blue-text {color: #000000;}</style><h1 class="red-text">I am red!</h1><h1 class="orchid-text">I am orchid!</h1><h1…

PowerShell: Add Local Group Members Onto a Server List

Sometimes, the GUI method of accomplishing tasks is too arduous and error prone. Thus, these…