There are many reasons one might want to establish a workflow in which they can quickly launch PowerShell or the ISE with alternative credentials from their interactive session, such as executing a script with a more privileged user context. To do so, create a script like the one below:
# Specify user name
$user = "<INSERT USERNAME>"
# Determine & affix domain name
$domain = [System.DirectoryServices.ActiveDirectory.Domain]::GetCurrentDomain()
$user = Join-Path $domain $user
# Execute ISE as other user
Start-Process PowerShell.exe -Credential $user -NoNewWindow -ArgumentList "Start-Process powershell_ise.exe -Verb runAs"
Then, create a shortcut to execute the script. The target command should be as follows:
Powershell.exe -ExecutionPolicy Bypass -File “<INSERT PATH>”
Upon executing this shortcut, you will be prompted for credentials like so:
To validate that your instance is within the new user context, use the following snippet:
[Security.Principal.WindowsIdentity]::GetCurrent().Name
This is an efficient means to run a script as a different user within a single interactive session.