How to automatically log in the system without entering password at startup in Windows 8 (PowerShell)

 Introduction

This PowerShell script sample shows how to automatically log in the system without entering password at startup in Windows 8.

Scenarios

A Microsoft account user must enter a password or a pin to log in the system when it starts up. Sometimes it seems not very convenient, this script is to log in the system without password when the system starts up.

Script

Step 1: Right click script and select Run with PowerShell.

Step 2: Then enter the current user password, next time you can log in automatically when the system starts up.

Here are some code snippets for your reference.

PowerShell
Edit|Remove
#Get user password 
$SecurePassword= read-host -Prompt "Please enter current user password" -AsSecureString
$password = [Runtime.InteropServices.Marshal]::PtrToStringAuto([Runtime.InteropServices.Marshal]::SecureStringToBSTR($SecurePassword));
$username = whoami
#Get default domain or computer name
$defaultdomain = ($username -split "\\")[0]
#Get current user name
$defaultuser = ($env:USERPROFILE -split "\\")[2]
#Change registry key values
$path = "HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon"
New-ItemProperty -Path $path -name "AutoAdminLogon"  -PropertyType string  -ErrorAction SilentlyContinue
Set-ItemProperty -path $path -name "AutoAdminLogon" -Value 1 
New-ItemProperty -Path $path -name "DefaultDomainName" -PropertyType string -ErrorAction SilentlyContinue
Set-ItemProperty -Path $path -name "DefaultDomainName" -Value $defaultdomain
New-ItemProperty -Path $path -name "DefaultuserName"  -PropertyType string  -ErrorAction SilentlyContinue
Set-ItemProperty -Path $path -name "DefaultuserName" -Value   $defaultuser
New-ItemProperty -Path $path -name "DefaultPassword"  -PropertyType string  -ErrorAction SilentlyContinue
Set-ItemProperty -Path $path -name "DefaultPassword" -Value   $password
Write-Host "Set automatically login successfully when system starts up."


cmd /c pause

Prerequisite 

Windows 8 or later version

Microsoft All-In-One Script Framework is an automation script sample library for IT Professionals. The key value that All-In-One Script Framework is trying to deliver is Scenario-Focused Script Samples driven by IT Pros' real-world pains and needs. The team is monitoring all TechNet forums, IT Pros' support calls to Microsoft, and script requests submitted to TechNet Script Repository. We collect frequently asked IT scenarios, and create script samples to automate the tasks and save some time for IT Pros. The team of All-In-One Script Framework sincerely hope that these customer-driven automation script samples can help our IT community in this script-centric move.