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:

  1. create script (let's call init.ps1)
  2. put in actions want invoke user
  3. add execute right script $config_name
  4. 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"

more difficult way install winrm , use commands enter-pssession (examples in end of link: http://technet.microsoft.com/en-us/library/hh849707.aspx)


Comments

Popular posts from this blog

android - getbluetoothservice() called with no bluetoothmanagercallback -

sql - ASP.NET SqlDataSource, like on SelectCommand -

ios - Undefined symbols for architecture armv7: "_OBJC_CLASS_$_SSZipArchive" -