powershell - 使用启动进程在远程 Windows 机器上安装 awscli msi 包

标签 powershell amazon-web-services packer

我正在尝试使用加壳器在 Windows 机器上配置 awscli。要安装 awscli,请使用以下 PowerShell 脚本:

$download_url = 'https://s3.amazonaws.com/aws-cli/AWSCLI64.msi'
$downloaddestination = 'C:\Program Files\awscli.msi'
$checkpath='C:\Program Files\Amazon\AWSCLI'
if (Test-Path $downloaddestination) {
  # // File exists do nothing
} else {
  # // File does not exist download it
  (New-Object System.Net.WebClient).DownloadFile($download_url, $downloaddestination)
}
$env:SEE_MASK_NOZONECHECKS = 1
Start-Process $downloaddestination /qn -Wait | Out-Null
Start-Sleep -Seconds 60
if (Test-Path $checkpath) {
  Write-Host "awscli installed"
} else {
  Write-Host "Installation failed"
}

我无法安装 awscli,它无法安装 MSI 包,即使它能够下载 packege。

最佳答案

我使用 Python 安装 cli,它也使更新更容易。我通常使用 cloud formation,cloud formation 使用用户数据调用由 powershell 运行的脚本。

脚本如下所示:

mkdir c:\setup-downloads
cd \setup-downloads
curl https://www.python.org/ftp/python/3.7.3/python-3.7.3-amd64.exe --output python-inst.exe
.\python-inst.exe /quiet InstallAllUsers=1 PrependPath=1 Include_test=0
Start-Sleep -s 30
$env:Path += ";C:\Program Files\Python37"
$env:Path += ";C:\Program Files\Python37\Scripts"
pip3 install awscli

在某处创建一个目录 mkdir c:\setup-downloads 。切换到该目录 cd\setup-downloads 然后我使用 curl 下载 python:curl https://www.python.org/ftp/python/3.7.3/python-3.7。 3-amd64.exe --output python-inst.exe

然后我使用quiet 模式运行安装,并将其设置为将自身安装到路径中,并为所有人安装 .\python-inst.exe/quiet InstallAllUsers=1 PrependPath=1 Include_test=0

我等待它完成 Start-Sleep -s 30 但是你需要重新s启动 powershell 才能真正访问 python 所以我运行以下命令来设置环境变量:

$env:Path += ";C:\Program Files\Python37"
$env:Path += ";C:\Program Files\Python37\Scripts"

现在我已经安装了 python,并且配置了环境变量,我可以按如下方式安装 cli:

pip3 install awscli

如果您运行 aws --version 它会起作用

关于powershell - 使用启动进程在远程 Windows 机器上安装 awscli msi 包,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36970984/

相关文章:

linux - Ubuntu 18.04/20.04 的预置文件卡在格式化磁盘屏幕上

packer - 如何在打包程序配置期间将文件复制到主机?

Powershell Azure : The term 'Get-AutomationConnection' is not recognized as the name of a cmdlet, 函数、脚本文件或可运行程序

amazon-web-services - 如何删除 AWS EMR 集群?

javascript - 使用带有 AWS S3 的签名请求并上传照片?

amazon-web-services - 我是否可以使CodePipeline仅在手动触发时执行

packer - 如何将 Packer.io ISO_URL 作为命令行参数传递

c# - 如何重新创建 PowerShell $profile 变量?它在自定义主机中为空

Powershell:从 $file.Fullname 中减去 $pwd

powershell - 如何识别已上传到 S3 且此后未更改的本地文件?