How to Run PowerShell as Different User?

Ever found yourself logged into a Windows workstation with your regular user account, only to realize you need to execute PowerShell commands with elevated privileges or different credentials? Very challenging!

In this tutorial, I will show you how to run PowerShell with different user credentials using various methods with examples.

Method 1: Using the GUI “Run as Different User” Option

The most intuitive approach involves using Windows’ built-in graphical interface. This method is ideal when you need a quick solution without needing to memorize command syntax.

To access this feature, locate the PowerShell icon in your Start menu or taskbar. Hold the Shift key and right-click on the PowerShell icon, then select “Run as different user” from the context menu. This opens a credential prompt where you can enter the desired username and password.

This method immediately launches a new PowerShell session under the specified credentials. I’ve used this countless times when troubleshooting domain issues while logged in with a regular user account, allowing me to quickly switch to domain administrator privileges without logging off my current session.

Check out Check Who Modified a File Last in Windows Using PowerShell

Method 2: Using the RunAs Command

The runas command provides a command-line approach that’s both powerful and flexible. This method allows you to specify credentials directly from the command prompt or an existing PowerShell session.

The basic syntax follows this pattern: runas /user:DOMAIN\USERNAME "powershell". For example, to run PowerShell as the domain administrator from Contoso Corporation, you would execute:

runas /user:CONTOSO\administrator "powershell"

The system prompts for the password, then launches a new PowerShell window under those credentials. This approach gives you granular control over which user context you’re operating under, making it invaluable for testing permissions or executing administrative tasks across different security contexts.

Advanced RunAs Options

You can enhance the runas command with additional parameters:

ParameterPurposeExample Usage
/netonlyUse credentials for network access onlyrunas /netonly /user:CONTOSO\svcaccount "powershell"
/profileLoad the user’s profilerunas /profile /user:CONTOSO\administrator "powershell"
/savecredSave credentials for future userunas /savecred /user:CONTOSO\administrator "powershell"

Read Delete User Profiles Using PowerShell in Windows 11

Method 3: Using Start-Process with Credential Parameter

For PowerShell purists, the Start-Process cmdlet offers a native PowerShell approach to launching processes with different credentials. This method integrates seamlessly with PowerShell scripts and automation workflows.

Before using this method, you need to create a credential object that securely stores the username and password. The Get-Credential cmdlet prompts for credentials and returns a PSCredential object:

$credential = Get-Credential -UserName "CONTOSO\administrator"
Start-Process powershell -Credential $credential

This approach opens a new PowerShell window running under the specified credentials. What makes this method particularly powerful is its integration with PowerShell’s security model—the credential object can be reused throughout your session, and you can programmatically construct credentials for automated scenarios.

Read Track User Login History on Windows Using PowerShell

Method 4: Using Invoke-Command for Remote Execution

When working with remote systems or when you need to execute specific commands rather than launch an interactive session, Invoke-Command provides the most flexible solution. This method is essential for enterprise environments where you manage multiple servers.

The Invoke-Command cmdlet allows you to execute PowerShell commands on remote computers using different credentials. Here’s how you can use it to run commands on a local machine with different credentials:

$credential = Get-Credential -UserName "CONTOSO\administrator"
Invoke-Command -ComputerName localhost -Credential $credential -ScriptBlock {
    Get-Service -Name "Windows Update"
    Get-WindowsFeature -Name "Web-Server"
}

This method executes the script block under the specified credentials and returns the results to your current session. I’ve found this particularly useful when deploying software across multiple servers or gathering system information from domain controllers while maintaining proper security boundaries.

As a PowerShell System administrator or an IT professional, you will get a requirement to run PowerShell as a different user. Here we saw four methods to do so.

The GUI method offers simplicity for occasional use, while the runas command provides command-line efficiency. The Start-Process cmdlet integrates seamlessly with PowerShell scripting, and Invoke-Command excels in remote management scenarios.

I hope this helps.

You may also like the following tutorials:

Leave a Comment

100 PowerShell cmdlets download free

100 POWERSHELL CMDLETS E-BOOK

FREE Download an eBook that contains 100 PowerShell cmdlets with complete script and examples.