0
powershell.exe Start-Process powershell.exe "set-executionpolicy" -Verb runAs

The above command will run a powershell window as admin and execute the command before it, however, if I want to make it say set-executionpolicy bypass, it will error out. How can I pass this parameter through the top command?

Below is the error I get when I pass said parameter:

    Start-Process : A positional parameter cannot be found that accepts argument
'bypass'.
At line:1 char:1
+ Start-Process powershell.exe set-executionpolicy bypass -Verb runAs
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidArgument: (:) [Start-Process], ParameterB
   indingException
    + FullyQualifiedErrorId : PositionalParameterNotFound,Microsoft.PowerShell
   .Commands.StartProcessCommand
2
  • And if you put it under quotation marks? "set-executionpolicy bypass" Commented May 11, 2017 at 14:28
  • I did. It didn't work. Commented May 11, 2017 at 14:39

2 Answers 2

1

Start-Process accepts an array of arguments in order to pass into created process. So, in order to launch an elevated Powershell that would execute a Set-ExecutionPolicy cmdlet you need to wrap the arguments into an array.

start-process -filepath powershell.exe -argumentlist @('-command','Set-ExecutionPolicy Bypass') -verb runas

As a side note, you probably want to set execution policy with -scope argument for it to actually be effective once that process ends.

Sign up to request clarification or add additional context in comments.

2 Comments

That works. Thank you. Can you explain the -scope part and where to put it?
get-help set-executionpolicy :) -scope determines which policy is to be modified. Values usable when starting elevated are localmachine and machinepolicy, the second can be overridden by domain policy IIRC.
1

You can use the –ExecutionPolicy switch directly on PowerShell.exe to bypass the execution policy.

powershell.exe –ExecutionPolicy Bypass

1 Comment

NONE of these answered the ORIGINAL question. How do you run from the "run" command an elevated PowerShell session ("Windows cannot find start-process)? You HAVE to use cmd /c originally, so how then do you run an elevated PowerShell that doe snot close from 'cmd/c'? It appears it's NOT possible.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.