In a lab environment, it's quite useful to have different users logged on automatically to speed up automation and testing. In a ConfigMgr (SCCM) environment, this can be configured during OSD, or afterwards via Run Scripts or a Configuration Baseline.
Note: This is intended for an isolated lab and test automation only. The username and password will be visible in clear text. Do NOT do this in any production environment.
Script to Enable AutoLogon via Registry
Here is a sample PowerShell script that enables AutoLogon via registry.
Note: The ForceAutoLogon value is purposely disabled since it breaks remote desktop (RDP) to the lab machine. If this setting is enabled RDP will log you in, and then immediately log you out. This took me longer to figure out than I'd like to admit 🙂
# Script to enable AutoLogon
$RegistryPath = 'HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon'
# Replace the below values
$DefaultDomainName = "<DOMAIN>"
$DefaultUsername = "<USERNAME>"
$DefaultPassword = "<PASSWORD>"
Set-ItemProperty $RegistryPath 'AutoAdminLogon' -Value "1" -Type String
Set-ItemProperty $RegistryPath 'AutoLogonCount' -Value "999" -Type String
Set-ItemProperty $RegistryPath 'DefaultDomainName' -Value $DefaultDomainName -type String
Set-ItemProperty $RegistryPath 'DefaultUsername' -Value $DefaultUsername -type String
Set-ItemProperty $RegistryPath 'DefaultPassword' -Value $DefaultPassword -type String
Set-ItemProperty $RegistryPath 'ForceAutoLogon' -Value "0" -type String
Set-ItemProperty $RegistryPath 'DisableCAD' -Value "1" -type Dword
Script to Disable AutoLogon via Registry
If you need to undo your changes, here is a script for that, too (kept the domain name)
# Script to remove AutoLogon
$RegistryPath = 'HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon'
Set-ItemProperty $RegistryPath 'AutoAdminLogon' -Value "0" -Type String
Set-ItemProperty $RegistryPath 'AutoLogonCount' -Value "0" -Type String
Set-ItemProperty $RegistryPath 'DefaultUsername' -Value "" -type String
Set-ItemProperty $RegistryPath 'DefaultDomainName' -Value "VIAMONSTRA" -type String
Set-ItemProperty $RegistryPath 'DefaultPassword' -Value "" -type String
Set-ItemProperty $RegistryPath 'ForceAutoLogon' -Value "0" -type String
Set-ItemProperty $RegistryPath 'DisableCAD' -Value "0" -type Dword