簡體   English   中英

從 CMD 運行 Powershell 7

[英]Run Powershell 7 from CMD

我有一個以管理員身份運行 Powershell 的 .bat 腳本,然后在與 .bat 文件相同的文件夾中運行 Powershell 腳本。 這工作得很好:

CMD /C powershell "Set-Location -PSPath '%CD%'; $Path = (Get-Location).Path; Set-Location ~; Start powershell -Verb RunAs -Args "-ExecutionPolicy ByPass" Set-Location -PSPath ' "$Path"'; & '".\Start_TOW_VM.ps1"'"""

我現在正在嘗試使用 Powershell 7 (pwsh) 代替,我認為它就像更改為這樣簡單:

CMD /C pwsh "Set-Location -PSPath '%CD%'; $Path = (Get-Location).Path; Set-Location ~; 開始 pwsh -Verb RunAs -Args "-ExecutionPolicy ByPass" Set-Location -PSPath ' "$Path"'; & '".\Start_TOW_VM.ps1"'"""

不幸的是,它不起作用並抱怨 Set-Location 命令,即使該命令在 Powershell 中工作得非常好 7. 我在這里做錯了什么?

想通了,解決辦法如下:

CMD /C pwsh -c 設置位置 -PSPath '%CD%'; $Path = (Get-Location).Path; 設置位置 ~;寫主機 $path; 開始 pwsh -Verb RunAs "-command Set-ExecutionPolicy ByPass; Set-Location -PSPath '"$Path"'; & '".\Start_TOW_VM.ps1"'"

只需在轉義的“.

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM