取得 PoserShell 安裝路徑


在 Windows 中預設的指令視窗(Command Line)大多還是命令提示字元(cmd),如果要切換的話就會需要找到其他指令視窗的執行路徑,在 Windows 上內建的還有 PowerShell ,那該如何查詢 PowerShell 的執行檔位置呢?

只要一行指令:
    
(Get-Command powershell).Source
    

範例輸出:
    
(Get-Command powershell).Source
C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe
    

那如果是基於 .NET 7 開發的 PowerShell Core — pwsh 呢?
    
(Get-Command pwsh).Source
    

範例輸出:
    
(Get-Command pwsh).Source
C:\Program Files\PowerShell\7\pwsh.exe
    

延伸閱讀:
pwsh 指令是什麼? pwsh 介紹和安裝教學

留言