windows - How to switch current user using powershell? -
my task create new windows local user, log in, using , actions. creating new user wasn't problem don't know how switch current user new one.
what did piece of script start new powershell window using new user:
$secpasswd = convertto-securestring $password -asplaintext -force $mycreds = new-object system.management.automation.pscredential ($config_name, $secpasswd) start-process powershell.exe -credential $mycreds -nonewwindow
is possible start doing rest of script in new window??
simple way following:
- create script (let's call init.ps1)
- put in actions want invoke user
- add execute right script $config_name
- change last line (-noexit debugging, without powershell close window after execution finish):
start-process powershell.exe -credential $mycreds -nonewwindow -argumentlist "-noexit -command full_path_to_script\init.ps1"
Comments
Post a Comment