[英]Run elevated powershell command from command prompt
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.上面的命令将以管理员身份运行一个 powershell 窗口并执行它之前的命令,但是,如果我想让它说
set-executionpolicy bypass
,它会出错。 How can I pass this parameter through the top command?如何通过 top 命令传递此参数?
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
您可以直接在PowerShell.exe
上使用–ExecutionPolicy
开关来绕过执行策略。
powershell.exe –ExecutionPolicy Bypass
Start-Process
accepts an array of arguments in order to pass into created process. Start-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.因此,为了启动一个提升的 Powershell 来执行
Set-ExecutionPolicy
cmdlet,您需要将参数包装到一个数组中。
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.作为旁注,您可能希望使用
-scope
参数设置执行策略,以便在该过程结束后真正生效。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.