Is there a way to switch user from powershell or cmd?

0

I have a Windows 10 machine, which auto login (using netplwiz) the Administrator account, and load some script at startup. Now I need sign-in with another user (User-1), after the Administrator account is signed in.
Is there a way to do this from powershell or cmd?
I need this process to run automatically.

Gev Hakobyan

Posted 2019-04-03T11:56:46.520

Reputation: 1

Script run nodejs aplication, which start and control other application. I want to use this trick , to split my windows server, because that application cant run as multiple process. – Gev Hakobyan – 2019-04-03T13:03:57.430

Why do you login automatically with administrator to run a script ? This ticks all the boxes of an "unwise solution" to a problem. You claim it is for nodejs, that does NOT need a Windows session (as in, Explorer and the gui running), so logging on as Administrator is not required! – user2531336 – 2019-04-03T13:07:30.557

Yes, but nodejs application is control other windows application (GUI application) , so for that i need to login to gui interface, and there is some specific env variables for every user. – Gev Hakobyan – 2019-04-03T13:19:26.093

only one use can be interactively logged on to any Windows box. Sure you can run a PowerShell script as another user, but that requires that user to enter creds. There is no skirting Windows security boundaries with PowerShell. well, not without hacking. You other option to run stuff as another user is using MS SysInternals psexec or use a logon script or scheduled task. – postanote – 2019-04-04T07:31:41.863

Answers

0

Do you search for something like this?

POWERSHELL CODE:

$Username = 'UserX'
$Password = 'P@ssW0rd'
$pass = ConvertTo-SecureString -AsPlainText $Password -Force #Not recommended, but if rights are set on that location you can use it like this, otherwise encrypt it (recommended).
$Cred = New-Object System.Management.Automation.PSCredential -ArgumentList $Username,$pass

#You can use it like this, or use it with other commands and ' -Credential ...' 
Invoke-Command -ComputerName "DeviceName" -Credential $Cred -ScriptBlock {#Your Code} 

Barry de Haan

Posted 2019-04-03T11:56:46.520

Reputation: 1