简体   繁体   English

如何通过 PowerShell 脚本安装 AWS CLI?

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

I am trying to check if aws cli is installed already, and install it if not present, I can't find any source on how to install it 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

After some research I was able to find a solution:经过一番研究,我找到了解决方案:

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

If you are using PowerShell 7, you can easily install it using the Windows Project Manager(WINGET).如果您使用的是 PowerShell 7,您可以使用 Windows 项目管理器 (WINGET) 轻松安装它。 Use following command >使用以下命令 >

winget install --id "Amazon.AWSCLI"

You can also look for it and other AWS utilites using the following command >您还可以使用以下命令查找它和其他 AWS 实用程序 >

winget search --name "aws"

Screenshot of the Shell Shell的截图

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM