簡體   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