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

CSS: How To Set Color Gradient and Animation to Text and Background

// Static color gradient .colorGradientClass { background-color: #ffffff !important; background-image: linear-gradient(315deg, #ffffff 0%, #d9d9d9 74%)…

PowerShell: How to Reset Windows Update Service

# resetWindowsUpdateService # This is a legacy method of reseting Windows Update # Since most…

Invoke Commands on Remote Computers [To Install Applications]

$computers=@( 'pc1', 'pc2' ) $commandString="choco install pgadmin4 -y --ignore-checksums" function invokeCommand{ param( $computers, $commandString, $credentials…