Auto-Logon After Windows-Reboot

by Jan 4, 2022

If your automation script needs to restart the machine, and you want to auto-logon after the reboot, here is a quick script that saves the logon credentials to the Windows registry:

# ask for logon credentials:
$cred = Get-Credential -Message 'Logon automatically'
$password = $cred.GetNetworkCredential().Password
$username = $cred.UserName

# save logon credentials to registry (WARNING: clear text password used):
$path = "HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon"
Set-ItemProperty -Path $path -Name AutoAdminLogon -Value 1
Set-ItemProperty -Path $path -Name DefaultPassword -Value $password
Set-ItemProperty -Path $path -Name DefaultUserName -Value $username

# restart machine and automatically log on: (remove -WhatIf to test-drive)
Restart-Computer -WhatIf

You can use the same approach if you want your machine to boot up and log in each time you turn it on.

Obviously, this technique may impose a security risk: the password is written in clear text to the registry. Use it carefully and only where appropriate.

Twitter This Tip! ReTweet this Tip!