Posted On March 7, 2023

PowerShell: Set Auto Logon

kimconnect 0 comments
blog.KimConnect.com >> Windows >> PowerShell: Set Auto Logon

Instead of running the GUI method (netplwiz), there’s a more efficient way to set auto logon for Windows XP, 7, 8, 10, 11 using these lines:

# setDefaultLogon.ps1
# version 0.01
# Missing feature to test whether creds are valid prior to committing... Will do that when I'm bored enough

$defaultAutologonUsername=$env:username
$defaultAutologonPassword=''

function setAutoLogon{	
	param(
		$defaultAutologonUsername=$env:username,
		$defaultAutologonPassword=''
	)
	$autoLogonRegHive='REGISTRY::HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon'
	try{
		Set-ItemProperty -Path $autoLogonRegHive -Name AutoAdminLogon -Value 1
		Set-ItemProperty -Path $autoLogonRegHive -Name DefaultUserName -Value $defaultAutologonUsername
		Set-ItemProperty -Path $autoLogonRegHive -Name DefaultPassword -Value $defaultAutologonPassword
		write-host "Default logon has been set with username $defaultAutologonUsername and password of $defaultAutologonPassword"
	}catch{
		write-warning $_
	}
}

setAutoLogon $defaultAutologonUsername $defaultAutologonPassword

Leave a Reply

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

Related Post

Dial Plans Decoded

() parenthesis enclose the dial plan | pipe means OR x represents a digit between…

Moving WSUS Content Staging Folder

Symptom: Bloated Wsus Staging Folder: Resolution: $wsusNewContentFolder='D:\Wsus\WsusContent'stop-service 'wsus service'&'C:\Program Files\Update Services\Tools\wsusutil.exe' movecontent $wsusNewContentFolder "$wsusNewContentFolder.log"start-service 'wsus…

Setup Multiple SMTP Servers

- Add SPF record for both SMTP servers that are authorized to send email for…