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: Quick Snippet to Remove Virtual Machine Snapshots in VMM

$vmNames=@( 'MACHINE1', 'MACHINE2' ) foreach($vmName in $vmNames){ $checkpoint = Get-SCVMCheckpoint -VM $vmName if($checkpoint){$checkpoint|%{Remove-SCVMCheckpoint -VMCheckpoint $_…

PowerShell: Get LastLogon Information of Computer Objects

$computernames=@( 'COMPUTER1', 'COMPUTER2' ) $computerLastLogon=foreach($computerName in $computernames){ get-adcomputer $computerName -Properties LastLogon|select Name,@{Name='LastLogon';e={[DateTime]::FromFileTime($_.LastLogon)}} } $computerLastLogon|sort -Property…

PowerShell: Discover Environment

One of the most common tasks of Active Directory cleanup is to perform a discovery…