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: Some Tricks in Using the Here-String to Declare Blocks of Code

Trigger COMMAND CLI from within PowerShell # Fastest way to list all files in a…

PowerShell: Add Office365 Records on DNS Servers

Make Changes to Internal DNS A. Delete Old CNAMES and MX Records Sample commands from…

PowerShell: Get Connected Port by Process Name

# getProcessConnectionPort.ps1 $computerlist=@' SQL1 SQL2 '@ $computernames=@($computerList -split "`n")|%{$_.Trim()} $processname='sqlservr' $state='Established' $results=@() foreach ($computername in…