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:
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:
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:
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.