Switch user powershell windows 10
- how to switch user in powershell
- how to use switch in powershell
- how to use replace in powershell
- how to switch user in windows 10 powershell
Powershell run command as different user with password!
Switch user in PowerShell like "sudo su -" in Unix/Linux
You need to write a custom function for this. You could use the following function (below), and put it in your PowerShell Profile.
to use this, you have to use an elevated PowerShell Console.
As you can see, you have a Parameter, which is set to by default (use your default username here).
Powershell run as logged in user
In you can say which values are allowed for the Parameter.
it will then depending on your parameter and read the correct username and password.
Then it will create a credential object, and a pssession as your desired user.
I do not recommend using Passwords as plain text in a script!
You should follow this to store your Passwords safely in the script
Example Output:
In this example you can see, when supplying no Value for , it will take your default user. when supplying a username which is in and in it will take that one
hope that wasn't too complicated.otherwise just ask :)
- how to use switch parameter in powershell
- how to change user name in powershell