11

If I run the following command in a Poweshell script file ($cmd refers to some executable):

Start-Process -FilePath $cmd -Verb RunAs Powershell

Then it executes OK

But if I slightly modify it:

Start-Process -NoNewWindow -FilePath $cmd -Verb RunAs Powershell 

Or like this:

Start-Process -FilePath $cmd -ArgumentList @("status") -Verb RunAs Powershell 

... then the command fails with the following error message:

Start-Process : Parameter set cannot be resolved using the specified named parameters.

I wonder why this format is not accepted and how should I modify the command to both specify an argument list and option "-Verb RunAs..."

Vagif Abilov
  • 9,835
  • 8
  • 55
  • 100
  • 1
    Guessing that `-NoNewWindow` and `-Verb RunAs` cannot be combined since you can elevate the session currently used. Going to check and see if that is true. I read that they are [incompatible](http://social.technet.microsoft.com/Forums/windowsserver/en-US/0ea76b46-8396-43e5-8caa-1cc929a74b8a/are-these-parameters-incompatibles?forum=winserverpowershell) – Matt Sep 08 '14 at 15:39
  • Oh I see, that is why! Thanks for the clarification. I could accept it as an answer if you rewrite your observation as an answer. – Vagif Abilov Sep 08 '14 at 16:06

2 Answers2

16

Guessing that -NoNewWindow and -Verb RunAs cannot be combined since you can't elevate the session currently used.

Upon futher investigation you are not the only one to look into this. I read that they are incompatible here

Depending on your motivation for running it like this you could just hide the window

Start-Process "powershell" -Verb "runas" -WindowStyle hidden

You can also look into PSSessions which can handle this type of thing as well. That could start an interactive session in the same window.

Matt
  • 45,022
  • 8
  • 78
  • 119
1

Maybe this helps you out:

$cmd = 'powershell.exe'
$arguments = "-NoLogo -NoProfile -WindowStyle Maximized"
Start-Process $cmd $arguments -Verb runAs

Another example from here:

Start-Process powershell -Credential mydomain\mydomainAdmin -ArgumentList '-noprofile -command &{Start-Process notepad -verb runas}'

Can you try it with your program and arguments and see how it goes?

Community
  • 1
  • 1
DarkLite1
  • 13,637
  • 40
  • 117
  • 214
  • It goes fine but it's not what I am after. I want to be able to pass "-NoNewWindow" option, and for some reasons I can't combine it with the Verb. The same goes for ArgumentList option. I am trying to understand why they can't be combined. – Vagif Abilov Sep 08 '14 at 14:39