# 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
Auto-Logon After Windows-Reboot
All Versions
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
标签:ItemProperty,Windows,Auto,After,Path,path,logon,cred From: https://blog.csdn.net/weixin_71228606/article/details/141144773