| by Arround The Web | No comments

Running PowerShell as Another User and Launching a Script

Unix operating systems have various options when it comes to scripting tools, unlike Windows. Windows have only one scripting tool, and that is PowerShell. In spite of this, it is more than capable of competing with all the other scripting tools. Windows allows different users to log in to PowerShell in the same session. After that, they can execute the scripts to perform the required functionality.

This post will illustrate a complete guide to resolve the mentioned query.

How to Run/Execute a PowerShell Script as a Different User?

In order to launch a PowerShell script as another user, follow the given instructions.

Step 1: Launch PowerShell

First, navigate to the Start menu and launch “PowerShell” from it:

Step 2: Launch the PowerShell Credential Request Pop-Up

Execute the given command to launch the “PowerShell Credential Request” window:

> start powershell -credential ""

Step 3: Log in as a Different User in PowerShell

After executing the given command, the “PowerShell Credential Request” window will be launched. Enter the other account credentials to launch PowerShell as a different user:

Step 4: Verify Logged in User

In order to verify whether the other user is logged in or not, execute the “whoami” command:

> whoami

The output verifies that the “linuxhint” user is logged in to the PowerShell.

Step 5: Run the PowerShell Script

Now, let’s run the PowerShell script by specifying the file path of the script. But make sure that the script you want to run must be in the newly logged-in user’s directory.

In order to run the script, write its complete path/address in the inverted commas and make use of the “&” invoke operator to execute the script:

> & "C:\Users\LinuxHint\Desktop\Test1.ps1"

As you can see, the specified PowerShell script has been executed by a different user.

Conclusion

To run the PowerShell as another user and launch a script, first, launch the “Windows PowerShell Credential Request” window by executing the “start powershell -credential “”” command. After that, enter the user credentials and log in to PowerShell as a different user. Now, you can easily launch the PowerShell script as a different user. This tutorial has provided a complete guide to running the PowerShell script as a different user.

Share Button

Source: linuxhint.com

Leave a Reply