Skip to main content

Reset Local Account Script

Change line 8 and 9.

# Check if the script is running as an administrator
if (-not ([Security.Principal.WindowsPrincipal][Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator)) {
    Write-Host "Please run this script as an administrator." -ForegroundColor Red
    exit
}

# Prompt for the username and password
$username = "test"
$password = "P@ssw0rdT3str3S3t"

# Define the output file path in C:\Temp
$outputFilePath = "C:\Temp\ResetPasswordLog.txt"

# Reset the local account password
try {
    $user = [ADSI]"WinNT://./$username,user"
    $user.SetPassword($password)
    $user.SetInfo()
    $output = "Password for $username has been reset."
    Write-Host $output -ForegroundColor Green
    $output | Out-File -FilePath $outputFilePath -Append
} catch {
    $output = "Error resetting password for $username : $_"
    Write-Host $output -ForegroundColor Red
    $output | Out-File -FilePath $outputFilePath -Append
}

# Output the file path where the log was saved
Write-Host "Log file saved at: $outputFilePath"