Set-LocalUser : An unspecified error occurred: status = 3221226252

Prashant Mishra 26 Reputation points
2025-01-15T16:09:03.5766667+00:00

I am trying to change user password based on below script but getting the error "Set-LocalUser : An unspecified error occurred: status = 3221226252".

$pks=Get-Date

foreach($pk in $pks){

$date=$pk.Day

$month=$pk.Month

$year=$pk.Year

$var01='prad'

$z=$year,$month, $date,$var01

$pp=-join $z

$pword = $pp | ConvertTo-SecureString -AsPlainText -Force

Set-LocalUser -Name "Admin" -Password $pword

}

Windows Server PowerShell
Windows Server PowerShell
Windows Server: A family of Microsoft server operating systems that support enterprise-level management, data storage, applications, and communications.PowerShell: A family of Microsoft task automation and configuration management frameworks consisting of a command-line shell and associated scripting language.
5,609 questions
{count} votes

2 answers

Sort by: Most helpful
  1. Rich Matheisen 47,581 Reputation points
    2025-01-15T16:44:18.4366667+00:00

    Are you trying to change the local admin account?

    Verify that account you're trying to modify:

    1. exists
    2. isn’t disabled
    3. isn’t locked

    And, lastly, that your account has local admin rights (and you run the code from an elevated PowerShell session -- i.e., start the session with "Run as administrator").

    1 person found this answer helpful.
    0 comments No comments

  2. Prashant Mishra 26 Reputation points
    2025-01-15T16:49:13.96+00:00

    Hi Rich,

    Yes, I am trying to changing local account password and account is exists and it is not disabled or Lock.


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.