![](/img/trans.png)
[英]Installed Node and Chocolatey on windows Admin powershell, but its not in regular the powershell
[英]Check if PowerShell 5 is installed and if not install it via Chocolatey
我有一個腳本,我想檢查是否安裝了Powershell 5,如果沒有,則通過Chocolaty安裝它。 我相信需要if
聲明。 是否有一種簡單的方法可以檢查PowerShell是否已更新,如果沒有運行此命令?
Set-ExecutionPolicy unresricted
iex ((New-Object
System.Net.WebClient).DownloadString('https://chocolatey.org/install.ps1'))
choco install powershell -y
choco upgrade powershell -y
您可以使用它來檢查版本:
If ($PSVersionTable.PSVersion.Major -lt 5) {
iex ((New-Object System.Net.WebClient).DownloadString('https://chocolatey.org/install.ps1'))
choco install powershell -y
choco upgrade powershell -y
}
我相信您需要從腳本外部更改執行策略,以使其既有效又無法交互。 通過運行腳本執行以下操作:
PowerShell.exe -ExecutionPolicy Bypass -File yourscript.ps1
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.