I am trying to use packer to provision awscli on a Windows machine. To install the awscli is use the following PowerShell script:
$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"
}
I am unable to install awscli, its getting failed to install the MSI package even though its able to download the packege.
I use Python to install the cli, it makes updating easier too. I normally use cloud formation, cloud formation uses the userdata to invoke a script that is run by powershell.
The script looks like this:
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
Create a directory somewhere mkdir c:\setup-downloads . Change to that directory cd \setup-downloads I then use curl to download python: curl https://www.python.org/ftp/python/3.7.3/python-3.7.3-amd64.exe --output python-inst.exe
Then I run the install using quiet mode, and I set it up to install itself into the path, and installed for everyone .\python-inst.exe /quiet InstallAllUsers=1 PrependPath=1 Include_test=0
I wait for this to finish Start-Sleep -s 30 But you need to restart the powershell to actually access python so I run the following to set the environment variables:
$env:Path += ";C:\Program Files\Python37"
$env:Path += ";C:\Program Files\Python37\Scripts"
Now that I have python installed, and the environment variables configured I can install the cli as follows:
pip3 install awscli
If you run aws --version it works
I tried #Jasons answer, calling the PowerShell file from an autoattend syncronusCommand block, however, I could not get pip3 command to be recognised.. setting the python env path inline I felt was a little hacky.
Check out - https://www.python.org/download/releases/2.5/msi/ - which explains that when using an MSI file the - installation can be initiated programmatically.
My PowerShell file now looks like this
Invoke-WebRequest -Uri https://awscli.amazonaws.com/AWSCLIV2.msi -Outfile "C:\aws.msi"
Start-Process -Wait -FilePath msiexec -ArgumentList /i, "c:\aws.msi", /qn
Now I have automated the install of aws cli on windows server.
I would suggest changing the approach and installing aws cli via pip the Python package manager that comes with the default Python installation.
Follow this guide to install Python silently on windows. Then you can just run the command below and it will install the awscli.
pip install awscli
You can use pip on windows, it's easy:
1. download and Install Python 2.7 for Win x64 in Python27 folder (default) [I had trouble with Python3.0 but I may have installed it wrong]
https://www.python.org/downloads/
2. in control panel, system, advanced settings add (ie., "new") to the user or system variable:
PYTHONPATH %PYTHONPATH%;C:\Python27\Lib
3. in control panel, system, advanced settings, edit the system PATH variable and add at the end:
;C:\Python27;C:\Python27\Scripts;C:\Program Files\Amazon\AWSCLI\
4. download the awscli package from
https://s3.amazonaws.com/aws-cli/AWSCLI64.msi
5. now you can run in the Windows DOS Command box: "pip install --upgrade awscli"
6. you can run cli commands in Windows DOS Command box, powershell or powershell ise. First run "aws configure" in powershell or win/dos command box
7. then you can run any CLI or CLI SDK command in powershell ise
Related
Yarn's not recognized as a cmd command.
I tried installing it globally with 'npm install -g yarn' and adding a path variable to "C:\Users[user]\AppData\Roaming\npm\yarn".
Any other suggestions?
First thing first, you should check you have 16+ node.js installed and, you can check it with
node -v
If it's valid,
run the npm config get prefix it'll give you a path CTRL+C this path
Open the start search and type in env and then click "Edit the system environment variables"
Modify the Environment variables
Add the copied path to you PATH as new
After this you should be good, but if the PS is cannot load the Yarn run this command
Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope CurrentUser
Here a few things you can try:
You may need to close and reopen the Powershell windows because newly added environment variables or updates to them are not automatically reflected to already open shell windows.
Check if your path is correct: it normally is C:\Users\endo\AppData\Roaming\npm on my PC, not C:\Users\endo\AppData\Roaming\npm\yarn as you mentioned.
Try running yarn.cmd or yarn.ps1.
Try CMD instead of Powershell, see if it works that way.
Version Anaconda 4.8.3
What I cannot do:
I can't activate any environment from powershell.
conda activate base
What I can do:
conda env list
conda create -n xxx conda remove -n xxx
I have tried many solutions, but they turn out to be useless:
conda init powershell
restart powershell
conda activate
conda update -n base conda and redo 1
conda install -n root -c pscondaenvs pscondaenvs
Set-ExecutionPolicy RemoteSigned
Run activate base
The result of running conda activate
You don't need Admin permission.
Once you install Anaconda or Miniconda on Windows, open a Anaconda Powershell Prompt from Start Menu.
Or, If you don't see it there, then assuming you have installed
miniconda3 at path C:\miniconda3\4.9.2, do:
powershell -ExecutionPolicy ByPass -NoExit -Command "& 'C:\miniconda3\4.9.2\shell\condabin\conda-hook.ps1' ; conda activate 'C:\miniconda3\4.9.2' "
Now try:
conda init powershell
and reopen powershell.
Additional note: By default conda will autoactivate itself, when we open terminal. If you prefer not, then disable auto-activation with:
conda config --set auto_activate_base false
Open a Anaconda Powershell Prompt from Start Menu.
Now Try:
conda init powershell
Now restart the powershell, if find some error like this in powershell:
\WindowsPowerShell\profile.ps1 cannot be loaded because running scripts is disabled on this system. For more information, see about_Execution_Policies at https:/go.microsoft.com/fwlink/?LinkID=135170. At line:1 char:3
Then change the execution policy. Type this code to powershell:
Set-ExecutionPolicy -ExecutionPolicy RemoteSigned
To find more with execution policy you can visit this link.
Here is my easier solution which works with Anaconda, Miniconda, and even Miniforge:
Open Powershell and browse to condabin folder in your conda installation directory, for example: C:\Users\<username>\anaconda3\condabin
Run ./conda init powershell in that folder, and re-open the powershell.
Please note: If you encountered ps1 cannot be loaded because running scripts is disabled on this system, simply run the Powershell as Administrator and enter the following: Set-ExecutionPolicy -Scope CurrentUser -ExecutionPolicy Unrestricted
Restart the Powershell & Enjoy!
When you use Anaconda or Miniconda type in Anacondaprompt:
conda init powershell
In order to activate conda on Powershell, I just executed this command:
C:\Users\<username>\anaconda3\shell\condabin\conda-hook.ps1
Then I could see all environments without needing to restart Powershell.
conda env list
conda activate base
So you need to basically just run the conda-hook.ps1 script.
Encountered the same problem. The trick is to make sure that the environment is included in the PATH variable of Windows Powershell. To view the PATH variables enter the following in the powershell:
$env:Path.split(';')
If the environment you desire doesn't show up in the output list, as in
.....
.....
..../envs/yourEnv/...
.....
run the following command on cmd:
conda init powershell
then restart _Anaconda Powershell,
then:
conda activate yourEnv
Hopefully, now the conda prompt should now show your desired environment.
To solve the problem without changing te security policy on powershell, you need to be on powershell 7. Powershell 7 will let you use a \WindowsPowerShell\profile.ps1 file as startup script with default (restricted) security policy settings. Windows Powershell is by default (on windows 10 at 14-08-2022) version 5.x.
Check your powershell version with
$PSVersionTable
If you're still on powershell 5, install powershell from the windows store. This will install powershell 7 alongside powershell 5. It will probably be called Powershell instead of Windows Powershell. Or if you're not allowed to use the windows store, ask IT to install it for you. Check the version again in the new powershell.
After this, we can follow the answer of prashant:
Open Anaconda prompt and run
conda init powershell
To stop conda starting by default run
conda config --set auto_activate_base false
& 'C:\ProgramData\Miniconda3\shell\condabin\conda-hook.ps1'; conda activate 'C:\ProgramData\Miniconda3'
This is the command found in Anaconda Powershell Prompt (Miniconda3).lnk on my computer.
On my machine, I can enter the environment anywhere by executing these two commands.
I am attempting to use Chocolatey to install an MSI package via Powershell. Following all the documentation and examples, my setup looks like this:
chocolateyinstall.ps1
$ErrorActionPreference = 'Stop';
$fileLocation = Join-Path $toolsDir 'installer.msi'
$pp = Get-PackageParameters
Write-Output ("Keys count is : ${pp}")
if (!$pp['defaultName']) { Write-Error "Please provide a default name"; exit -1; }
...
When I run this command:
choco install .\st-installer.1.6.7.nupkg --force --params "'/defaultName:Bob'"
the powershell throws my error:
ERROR: The running command stopped because the preference variable "ErrorActionPreference" or common parameter is set to Stop: Please provide a default name
However if I run the command with the -d switch, Powershell shows me: packageParameters: '/defaultName:',
What am I doing wrong here? I've tried every variation of quotations around the params, installation argument instead of param package. I don't know what else I can do.
I've run into this before when testing packages locally, where my additional parameter values aren't referenced like you're seeing. I don't know why it happens, but don't reference a hard path to the nupkg. Instead, set the source parameter to the directory the package is in (relative path is fine), and then install the package by it's package ID as though you were installing from Chocolatey.org. For example, if the package is in your current directory:
cinst -y st-installer --params "'/defaultName:Bob'" -s .
I'm not sure what version of Chocolatey you're on but if I try installing a package by pointing to the nupkg on disk, I get a warning about preferring the -s parameter and package ID instead of referencing the package file.
I'm working to automate the install of some of our software and was able to do so using a batch file, but was having issues with getting the silent install working in PowerShell.
The batch file which is working properly to install the application is:
#echo off
start /wait Setup.exe -s -l=EN
echo %errorlevel%
I've tried the following code in PowerShell, but the GUI installer will appear when I attempt to run it.
cmd.exe /c "Start /wait c:\temp\application\setup.exe -s -l=EN"
I don't receive any error messages when running the PowerShell script, it just doesn't install the application silently.
Try this:
&{ "c:\temp\application\setup.exe" -s -l=EN }
This should call an external Commandline command from Powershell.
The braces are not always strictly necessary either if you are just running the command and not doing anything with the output the following would likely work
& c:\temp\application\setup.exe -s -l=EN
I'd like to have both an Anaconda python v2 and python v3 environment. I've run both Anaconda installers, working in Microsoft's powershell. Then to create the python3 env I run:
PS C:\Users\jo> conda create -n py3 python=3.4
Fetching package metadata: ....
Solving package specifications: .
Package plan for installation in environment C:\Anaconda\envs\py3:
The following NEW packages will be INSTALLED:
pip: 6.1.1-py34_0
python: 3.4.3-0
setuptools: 15.2-py34_0
Proceed ([y]/n)? y
Linking packages ...
[ COMPLETE ]|##################################################| 100%
#
# To activate this environment, use:
# > activate py3
#
However activating this env ignores the new env:
PS C:\Users\jo> activate py3
Activating environment "py3"...
PS C:\Users\jo> python
Python 2.7.9 |Anaconda 2.2.0 (64-bit)| (default, Dec 18 2014, 16:57:52) [MSC v.1500 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
Anaconda is brought to you by Continuum Analytics.
Please check out: http://continuum.io/thanks and https://binstar.org
>>>
.. as we see by looking at which is current in the list of installed envs:
PS C:\Users\jo> conda env list
# conda environments:
#
py3 C:\Anaconda\envs\py3
root * C:\Anaconda
When sanity reigns, the activate command performs this switch by modifying the path variable. Is there something else I need to do in this environment to get it to work?
Switch first to cmd, then activate py3:
> cmd
> activate py3
If you run a cmd.exe shell script from PowerShell (a batch file), PowerShell spawns an instance of cmd.exe to run the script. If the batch file sets environment variables, they exist only in the spawned cmd.exe instance. Once that instance terminates (i.e., when the script ends), the environment variables do not propagate to the calling process (PowerShell, in this case). This is by design.
If you want to propagate environment variables, you can use the following Invoke-CmdScript function in PowerShell:
function Invoke-CmdScript {
param(
[String] $scriptName
)
$cmdLine = """$scriptName"" $args & set"
& $Env:SystemRoot\system32\cmd.exe /c $cmdLine |
Select-String '^([^=]*)=(.*)$' | ForEach-Object {
$varName = $_.Matches[0].Groups[1].Value
$varValue = $_.Matches[0].Groups[2].Value
Set-Item Env:$varName $varValue
}
}
Some more information about this in the following article:
Windows IT Pro: Take Charge of Environment Variables in PowerShell