Computer login using powershell

This topic contains 4 replies, has 3 voices, and was last updated by Profile photo of Cody Everingham Cody Everingham 8 months ago.

Viewing 5 posts - 1 through 5 (of 5 total)
  • Author
    Posts
  • #34298
    Profile photo of Cody Everingham
    Cody Everingham
    Participant

    Is there a way to make a computer login or switch user using invoke-command?

    #34307
    Profile photo of Don Jones
    Don Jones
    Keymaster

    Not really. You can force a logoff using Win32_OperatingSystem's Win32Shutdown() method, but you can't force a logon. Logon is handled by a privileged, secure process and is pretty much explicitly designed to not allow what you're trying, because that'd be a great way to hack a computer.

    #34322
    Profile photo of Matt Bloomfield
    Matt Bloomfield
    Participant

    You could set the registry keys for autologon and then force a reboot.
    Obviously it's not production worthy, you don't want plain text passwords in the registry and you'll have to clean up the entries afterwards to prevent it logging in with that user every time you reboot. However, in a pinch, it'll do what you want:

    Invoke-Command -ComputerName aComputer -ScriptBlock {
    
        Set-Location 'HKLM:\Software\Microsoft\Windows NT\CurrentVersion\Winlogon'
        New-ItemProperty -Path . -Name AutoAdminLogon -PropertyType String -Value 1
        New-ItemProperty -Path . -Name DefaultUserName -PropertyType String -Value 'CONTOSO\administrator'
        New-ItemProperty -Path . -Name DefaultPassword -PropertyType String -Value [email protected]'
        Restart-Computer -Force
       
    }
    
    #34325
    Profile photo of Don Jones
    Don Jones
    Keymaster

    Heh... "you could do this, but only crazy people do it in production!"

    Good point Matt; I'd kind of assumed AutoLogon wasn't the goal. But that's been in Windows forever and certainly works, albeit involving clear-text passwords in the least-secure database possible. And you can't make this switch users using the Fast User Switching functionality, but you could force a logoff after setting the AutoLogon, which would be similar.

    #34328
    Profile photo of Cody Everingham
    Cody Everingham
    Participant

    Thanks, now I know!

Viewing 5 posts - 1 through 5 (of 5 total)

You must be logged in to reply to this topic.