[英]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.