Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PowerShell does not recognize AWS CLI installed in the same script

I have installed aws cli using powershell script

 $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

When I try to print the aws --version it gives the below error.

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
+ ~~~
like image 282
mellifluous Avatar asked Dec 11 '25 02:12

mellifluous


2 Answers

I was able to fix this by adding the below line after installing aws cli:

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

complete code:

$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
like image 193
mellifluous Avatar answered Dec 13 '25 17:12

mellifluous


I was having the same issue on my Windows OS, after installing the .msi file from the aws official website. it is now solved by just passing the PATH of installed aws cli AWSCLIV2 to the system environment variable which is by default for me is C:\Program Files\Amazon\AWSCLIV2 you can do the same but if you customized the path while installation then use yours.

like image 44
Anurag Yadav Avatar answered Dec 13 '25 17:12

Anurag Yadav



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!