簡體   English   中英

如何通過 PowerShell 腳本安裝 AWS CLI?

[英]How to install AWS CLI through PowerShell script?

我正在嘗試檢查是否已經安裝了 aws cli,如果不存在則安裝它,我找不到任何關於如何通過 PowerShell 腳本安裝它的資源

function prereq {
    if ((Get-Command aws -ErrorAction SilentlyContinue) -eq $null) {
        Write-Host "Unable to find aws.exe in your PATH."
    } else {
    # Download from this link https://awscli.amazonaws.com/AWSCLIV2.msi
    # Install the AWSCLIV2.msi 
    # print aws cli version "aws --version"
    }
}

prereq

經過一番研究,我找到了解決方案:

function prereq {
    if ((Get-Command aws -ErrorAction SilentlyContinue) -eq $null) {
        Write-Host "Unable to find aws.exe in your PATH."
    } else {
        $command = "[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12"
        Invoke-Expression $command
        Invoke-WebRequest -Uri "https://awscli.amazonaws.com/AWSCLIV2.msi" -Outfile C:\AWSCLIV2.msi
        $arguments = "/i `"C:\AWSCLIV2.msi`" /quiet"
        Start-Process msiexec.exe -ArgumentList $arguments -Wait
    }
}

prereq

如果您使用的是 PowerShell 7,您可以使用 Windows 項目管理器 (WINGET) 輕松安裝它。 使用以下命令 >

winget install --id "Amazon.AWSCLI"

您還可以使用以下命令查找它和其他 AWS 實用程序 >

winget search --name "aws"

Shell的截圖

暫無
暫無

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

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