Posted On July 2, 2020

PowerShell: Setting or Resetting User Password

kimconnect 0 comments
blog.KimConnect.com >> Codes >> PowerShell: Setting or Resetting User Password
$username='dragoncoin'
$newPassword='SomeComplexPasswordHere'

function resetPassword($username,$password){
    if($env:userdnsdomain){
        try{
            Unlock-ADAccount -Identity $username
            Set-ADAccountPassword -Identity $username -Reset -NewPassword (ConvertTo-SecureString -AsPlainText "$password" -Force) -ea Stop
            }
        catch{
            write-warning "$($error[0])"
            try{
                net user /domain $username /active=yes
                net user /domain $username $password
                }
            catch{
                write-warning "$($error[0])"
                }
            }
        }
    else{
        net user $username /active=yes
        net user $username $password
        }
}

Leave a Reply

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

Related Post

How to Install PowerShell Module on An Offlined Computer

# Download the desired module onto a 'jump host' (an intermediary computer that has access…

How To Move WordPress Site To Kubernetes Cluster

a. Create backups of source files and database - Logon to Current Hosting Provider to…

Basic HTML and HTML5: Use HTML5 to Require a Field

<h2>CatPhotoApp</h2><main><p>Click here to view more <a href="#">cat photos</a>.</p><a href="#"><img src="https://bit.ly/fcc-relaxing-cat" alt="A cute orange cat lying…
Other project: DragonCoin.com