Right-Click Run As option

by netcodernaut at 2013-02-24 00:10:09

On my Server 2003 O/S with PS 2.0, when I right click on the PS icon, I am given the option to Run as a user of my choosing. I typically chose a Dev Admin account that our IT sets up for developer systems.

However, on my new Windows7 box with PS 3.0, I am only given the option to “Run as Administrator”. Is there a way to get PS 3.0 to give the user the option to Run As a specific user such as a different user in the Admin group?

This matters for me because many of my scripts run MSBuild which creates files on the fly and assigns them to the “Administrator” account rather than the account I logged onto the computer with. This makes it difficult to work with the files from outside of Powershell. For instance, VisualStudio can’t create or delete files in a source tree after a build script has been run on that same source tree through PS when running as the “Administrator”.

Any suggestions would be appreciated.
by AlexBrassington at 2013-02-24 01:12:42
Not that I know of. That behaviour is based around Windows rather than Powershell. The Runas command is generally hidden away from you. The workaround I use in those situations where i have to use a different account regulary is to create a .bat script with a runas command in it:

Runas /user:“alexDomain\alexAccount” "%SystemRoot%\system32\WindowsPowerShell\v1.0\powershell.exe"
by stromnessian at 2013-02-24 12:16:13
Doesn’t shift + right click work?
by nohandle at 2013-02-24 12:26:02
The shift + right clisk seems to work only for executables for me. But I am sure it is possible to add entries to this menu.
by netcodernaut at 2013-02-24 23:15:05
Yup! Shift + right click was the answer I was looking for. Much thanks!
by Milo at 2013-02-25 01:55:43
or you can build in the option as a function on top of your powershell script…


function Test-Admin {
$currentUser = New-Object Security.Principal.WindowsPrincipal $([Security.Principal.WindowsIdentity]::GetCurrent())

if ((Test-Admin) -eq $false) {
if ($elevated)
# tried to elevate, did not work, aborting
else {
Start-Process powershell.exe -Verb RunAs -ArgumentList (’-noprofile -noexit -file “{0}” -elevated’ -f ($myinvocation.MyCommand.Definition))


‘running with full privileges’