繁体   English   中英

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

[英]PowerShell does not recognize AWS CLI installed in the same script

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

 $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
+ ~~~

在安装 aws cli 后,我可以通过添加以下行来解决此问题:

$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

当我在 Visual Studio 代码中编写 aws 配置并按下显示以下错误 aws 的 entet 时:术语“aws”未被识别为 cmdlet、function、脚本文件或可运行程序的名称。 检查名称的拼写,或者如果包含路径,请验证路径是否正确并重试。 在行:1 字符:1

  • aws 配置

我可以在 fisual studiovo + CategoryInfo: ObjectNotFound: (aws:String) [], CommandNotFoundException + FullyQualifiedErrorId: CommandNotFoundException 中解决这个问题

暂无
暂无

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

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