mellifluous
mellifluous

Reputation: 2975

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

Upvotes: 14

Views: 44646

Answers (2)

Anurag Yadav
Anurag Yadav

Reputation: 71

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.

Upvotes: 2

mellifluous
mellifluous

Reputation: 2975

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

Upvotes: 36

Related Questions