繁体   English   中英

从命令提示符运行提升的 powershell 命令

[英]Run elevated powershell command from command prompt

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

上面的命令将以管理员身份运行一个 powershell 窗口并执行它之前的命令,但是,如果我想让它说set-executionpolicy bypass ,它会出错。 如何通过 top 命令传递此参数?

以下是我在传递所述参数时得到的错误:

    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接受参数数组以传递给创建的进程。 因此,为了启动一个提升的 Powershell 来执行Set-ExecutionPolicy cmdlet,您需要将参数包装到一个数组中。

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

作为旁注,您可能希望使用-scope参数设置执行策略,以便在该过程结束后真正生效。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM