How to AutoLogon Microsoft Windows using PowerShell

Home > Blogs > PowerShell > How to AutoLogon Microsoft Windows using PowerShell

How to AutoLogon Microsoft Windows using PowerShell

Like This Blog 4 Jason Helmick
Added by November 26, 2012

Do you ever just want Windows Server, or client for that matter, to automatically logon? This is a horrible idea in production and violates every security rule you can imagine. So don’t do this!  But…

I build a lot of test/dev environments and want my Servers to automatically logon and start PowerShell. In this blog I’ll show you the old-skool way of setting up auto logon for Windows. In the next blog, I’ll show you how to start PowerShell automatically on Windows Server Core rather than the old command prompt.

Remember I said old-skool? Yea, this comes from the old WinNT 4 days. You can setup AutoLogon in an old registry key “HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon”. PowerShell makes this a snap. You need to add the keys for Autologon, DefaultUserName and DefaultPassword. (Warning – the password will be stored in plain text in the registry)

PS C:\> New-ItemProperty -Path 'HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon' -Name AutoAdminLogon -Value 1

PS C:\> New-ItemProperty -Path 'HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon' -Name DefaultUserName -Value "Company\Administrator"

PS C:\> New-ItemProperty -Path 'HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon' -Name DefaultPassword -Value P@ssw0rd

Of course, if you have several computers you need to auto logon you can use PowerShell Remoting. 

PS C:\> Invoke-Command -ComputerName S1, S2 -ScriptBlock {New-ItemProperty -Path 'HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon' -Name AutoAdminLogon -Value 1}

PS C:\> Invoke-Command -ComputerName S1, S2 -ScriptBlock {New-ItemProperty -Path 'HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon' -Name DefaultUserName -Value "Company\Administrator"}

PS C:\> Invoke-Command -ComputerName S1, S2 -ScriptBlock {New-ItemProperty -Path 'HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon' -Name DefaultPassword -Value "P@ssw0rd"}

Now use your power wisely 😉

Knowledge is PowerShell

Jason Helmick
Director of PowerShell Technologies
Interface Technical Training

Videos You May Like

Creating Users and Managing Passwords in Microsoft Office 365

0 642 3

In this Office 365 training video, instructor Spike Xavier demonstrates how to create users and manage passwords in Office 365.   For instructor-led Office 365 training classes, see our course schedulle: Spike Xavier SharePoint Instructor – Interface Technical Training Phoenix, AZ 20347: Enabling and Managing Office 365    

How to Reset a Windows Client Secure Channel Password

0 2016 3

See our class schedule for complete Course Schedule Training. Instructor: Rick Trader How to Reset a Windows Client Secure Channel Password I’m sure you’ve ran into a situation where a user is attempting to log into a machine but they’re getting prompted that there’s no secure password or a secure channel for the client computer … Continue reading How to Reset a Windows Client Secure Channel Password

Detailed Forensic Investigation of Malware Infections – April 21, 2015

4 608 5

How does an investigator hunt down and identify unknown malware? In this recording of our IT Security training webinar on April 21, 2015, Security expert Mike Danseglio (CISSP / CEH) performed several malware investigations on infected computers and identify symptoms, find root cause, and follow the leads to determine what’s happening. He demonstrated his preferred … Continue reading Detailed Forensic Investigation of Malware Infections – April 21, 2015

Write a Comment

See what people are saying...

  1. Avatar cleanmymac 3.10

    I like this article, because so much useful stuff on here : D.

  2. Avatar Mike

    Have used this parms a lot in the past – now with powershell – may need to use in VDI link clone env. Anyone know how to initiate the logon process without rebooting?

  3. Pingback: How to make PowerShell the default console for Windows Server Core

  4. Avatar CarelessBear

    Be careful using the NEW-ITemProperty Cmdlet. It will not modify an already existing CMDLET’s name. SET-ItemPRoperty will create if none exists and modify if one exists. Explicitly declaring the Value type is also a good practice as system behavior can vary. Typically default is String REG_SZ, but sometimes it can be a DWORD for no reason I am aware of.

    What I am not sure of is if SET-ItemPRoperty will preserve a Value Type of an existing Value or if it will modify it and if unspecified do w/e it feels like? Should test that out….

Share your thoughts...

Please fill out the comment form below to post a reply.