PowerShell无法识别安装在同一脚本中的AWS CLI

3bygqnnd  于 5个月前  发布在  Shell
关注(0)|答案(2)|浏览(63)

我已经使用powershell脚本安装了aws

$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
 aws --version

字符串
当我尝试打印aws --version时,它给出了下面的错误。

aws : The term 'aws' is not recognized as the name of a cmdlet, function, 
script file, or operable program. Check the spelling of the name, or if a path 
was included, verify that the path is correct and try again.
At line:1 char:1
+ aws
+ ~~~

icomxhvb

icomxhvb1#

我能够通过在安装AWS服务器后添加下面的一行来解决这个问题:

$env:Path = [System.Environment]::GetEnvironmentVariable("Path","Machine")

字符串
完整代码:

$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
$env:Path = [System.Environment]::GetEnvironmentVariable("Path","Machine")
aws --version
aws s3 ls

aemubtdh

aemubtdh2#

我在我的Windows操作系统上遇到了同样的问题,在从aws official website安装**.msi文件之后。现在只需将安装的aws安装程序AWSCLIV2PATH**传递到system environment variable就可以解决这个问题,默认情况下,我是C:\Program Files\Amazon\AWSCLIV2,你可以做同样的事情,但如果你在安装时自定义了路径,那么就使用你的路径。

相关问题