Install msi file using powershell script - amazon-web-services

I am new in power shell. i need to install file using powershell. My msi file location is C:\Amazon\AWSCLIV2.
I have tried with the powershell script
Start-Process C:\Amazon\AWSCLIV2.msi
msiexec /i "C:\Amazon\AWSCLIV2.msi" /qn+
When i executing the above script gets installation windows. ie; click to next to install(Displayed window) the above msi file(i need to remove this window). but actually i want, installation should works automatically when executing powershell script.
So i need to execute installation using powershell script.

Can you try this:
$arguments = "/i `"C:\Amazon\AWSCLIV2.msi`" /quiet"
Start-Process msiexec.exe -ArgumentList $arguments -Wait

Related

Executing PowerShell scripts via python

I have this PowerShell script and I have manually executed this
powershell -Command "C:\shellcommand.ps1"
I am writing it as subprocess.check_output("powershell -Command 'C:\shellcommand.ps1'")
I am getting result as C:\\shellcommand.ps1\r\n.
Actually I am trying to run a batch file from the script. Manually it is running.
Could you please help me how I can able to call this in python
Parameter -Command is for cmdlets, and -File is for scripts.
Try This:
powershell -ExecutionPolicy ByPass -File"C:\shellcommand.ps1"
I think it will work for you.

URL Rewrite 2.0 installation fails on Docker

I'm trying to get URL Rewrite 2.0 installed using this Dockerfile:
FROM microsoft/aspnet:4.6.2
WORKDIR /inetpub/wwwroot
COPY obj/Docker/publish .
ADD https://download.microsoft.com/download/C/9/E/C9E8180D-4E51-40A6-A9BF-776990D8BCA9/rewrite_amd64.msi /install/rewrite_amd64.msi
RUN net start MSIServer
RUN msiexec.exe /i c:\install\rewrite_amd64.msi /quiet /passive /qn /L*v "C:\package.log"
When I build the container image, I see this error message:
The Windows Installer Service could not be accessed. This can occur if the Windows Installer is not correctly installed. Contact your support personnel for assistance.
Looking at package.log after running the container, I see this:
SI (c) (30:A4) [08:32:10:438]: Failed to connect to server. Error: 0x80040150
SI (c) (30:A4) [08:32:10:438]: Note: 1: 2774 2: 0x80040150: 2774 2: 0x80040150
Executing net start msiserver on the running container returns a message that the service is already started, and Google says 0x80040150 could be a problem reading the registry.
Is it expected that installing URL Rewrite this way should work, or do I need to elevate permissions somehow?
Update: Running the same msiexec command on the running container successfully installs URL Rewrite.
I finally figured it out thanks to this article. Using PowerShell to run msiexec with the appropriate switches works. Oddly, it threw "Unable to connect to the remote server" when trying to also download the MSI using PowerShell, so I resorted to using ADD.
Here's the relevant portion of my Dockerfile:
WORKDIR /install
ADD https://download.microsoft.com/download/C/9/E/C9E8180D-4E51-40A6-A9BF-776990D8BCA9/rewrite_amd64.msi rewrite_amd64.msi
RUN Write-Host 'Installing URL Rewrite' ; \
Start-Process msiexec.exe -ArgumentList '/i', 'rewrite_amd64.msi', '/quiet', '/norestart' -NoNewWindow -Wait

Installing Google Cloud SDK, what is the path to the rc file?

https://cloud.google.com/sdk/docs/quickstart-mac-os-x
I downloaded the tar, and ran the install.sh
Next I got this message, however I don't see any rc / .rc file?
To update your SDK installation to the latest version [162.0.1], run:
$ gcloud components update
Modify profile to update your $PATH and enable shell command
completion?
Do you want to continue (Y/n)? y
The Google Cloud SDK installer will now prompt you to update an rc
file to bring the Google Cloud CLIs into your environment.
Enter a path to an rc file to update, or leave blank to use
[/Users/leongaban/.zshrc]:
Leon, the Cloud SDK installer provides you an option to update your $PATH as well as install shell completion for commands in the Cloud SDK. This is done by adding few lines to your shell startup script (commonly known as a rc file).
Since you selected y to go forward with this step, the installer asks for the location of the rc file (i.e. shell startup script).
It has detected that you use zsh and hence it gives you the default option to update this file /Users/leongaban/.zshrc.
If instead you are using bash you would have to specify something like /Users/leongaban/.bashrc
You could also select n in the previous step and update $PATH and/or shell completion manually too.

Setup git via windows docker file

I write Dockerfile which is based on windowsnanoserver. I need to add to this image git. In order to achieve it I did the following:
RUN Invoke-WebRequest 'https://github.com/git-for-windows/git/releases/download/v2.12.2.windows.2/Git-2.12.2.2-64-bit.exe'
RUN Invoke-Expression "c:\Git-2.12.2.2-64-bit.exe"
But when I execute this lines via docker build, I receive following error message:
Invoke-Expression : The term 'c:\Git-2.12.2.2-64-bit.exe' 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.
I realize that this error message indicates that due to console nature of windows docker images I'll not be able to execute GUI installers. Unfortunately git doesn't have console installer. Chocolatey works fine under windowsservercore image but doesn't work at windowsnanoserver. In order to install git for windowsnanoserver I have idea to repeat in Dockerfile commands from chocolatey git installer which is fine for me, but still I'd like to know is there any simpler way to install git on windowsnanoserver?
I've solved issue with GUI through usage of MinGit and by putting information about mingit into environment/path variable. I've used following approach:
RUN Invoke-WebRequest 'https://github.com/git-for-windows/git/releases/download/v2.12.2.windows.2/MinGit-2.12.2.2-64-bit.zip' -OutFile MinGit.zip
RUN Expand-Archive c:\MinGit.zip -DestinationPath c:\MinGit; \
$env:PATH = $env:PATH + ';C:\MinGit\cmd\;C:\MinGit\cmd'; \
Set-ItemProperty -Path 'HKLM:\SYSTEM\CurrentControlSet\Control\Session Manager\Environment\' -Name Path -Value $env:PATH
You are correct, both Windows and Linux containers generally focus on running headless applications (i.e. without GUI).
It sounds like you want to create a container image based on the nanoserver image that has git?
Chocolatey is a great idea.
If you give me the broader context of your goals I can help you further.
Cheers :)
Installing to the docker image using Chocolatey worked for me as per this image: ehong
I addeded these lines to my Dockerfile:
ENV ChocolateyUseWindowsCompression false
RUN powershell Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Force
RUN powershell -NoProfile -ExecutionPolicy Bypass -Command "iex ((New-Object System.Net.WebClient).DownloadString('https://chocolatey.org/install.ps1'))" && SET "PATH=%PATH%;%ALLUSERSPROFILE%\chocolatey\bin"
RUN choco install git.install -y --no-progress
Call the git.setup.exe installation file with the parameters /? to list all possible switches.
To run a silent installation:
git.setup.exe /VERYSILENT /NORESTART /NOCANCEL /SP- /CLOSEAPPLICATIONS /RESTARTAPPLICATIONS
To do a customized installation:
run manually git installation with the parameter /SAVEINF="filename"
e.g:. git-2.xx.exe /SAVEINF="filename"
And then to repeat the installation with /LOADINF="filename"
e.g.: git.setup.exe /VERYSILENT /NORESTART /NOCANCEL /SP- /CLOSEAPPLICATIONS /RESTARTAPPLICATIONS /LOADINF="filename"
It's documented on:
Git: Silent-or-Unattended-Installation
You can download and use the Git Thumbdrive edition:
https://git-scm.com/download/win
look for the link under:
Git for Windows Portable ("thumbdrive edition")
E.G.: https://github.com/git-for-windows/git/releases/download/v2.23.0.windows.1/PortableGit-2.23.0-64-bit.7z.exe
Based on the answer of #Mariusz, the following lines install git into Windows image
# copy inf file
COPY resources/git-install.inf c:\git-install.inf
# get Git install file
RUN Invoke-WebRequest 'https://github.com/git-for-windows/git/releases/download/v2.30.1.windows.1/Git-2.30.1-64-bit.exe' -OutFile 'git.exe'; `
# install Git
Start-Process "c:\git.exe" -ArgumentList '/SP-', '/VERYSILENT', '/NORESTART', '/NOCANCEL', '/CLOSEAPPLICATIONS', '/RESTARTAPPLICATIONS', '/LOADINF=git-install.inf' -Wait -NoNewWindow; `
# delete files
Remove-Item -Force git-install.inf; `
Remove-Item -Force git.exe;

Setting up Bamboo SVN commit build trigger

Bamboo CI has a build in feature of having the subversion program trigger a build in bamboo when someone commits to the repository. I followed the instructions of what to put in the post commit hook but I am not sure what the 2 arguments are supposed to be for the postcommitbuildtrigger.sh file. Lets say the project name is TEST and the build name is TESTBUILD and the server url is http://localhost:8085. I wrote this in the post commit hook command line.
/<pathtopostcommit.sh> TEST TESTBUILD
Question
The post commit .sh file is on a windows machine. It could be because windows doesnt run .sh files but if thats so does anyone know how to set up this trigger on windows?
Also, I think this will trigger a build immediatly? Is is possible to trigger bamboo to run a poll instead so the build will obey the quiet period?
Have to write your own scripts. Bamboo only distributes mac and linux scripts.
Ok I wrote my own. It's so much nicer than subversion poll time-outs. Tested on:
VisualSvn Server 2.7.2;
Windows Web Server 2008 R2.
PowerShell 2.0
BambooWebApiTrigger.bat
A batch file runner for PowerShell in C:\SvnHooks\:
#echo OFF
rem this file just makes spawning powershell from VisualSvn a tad easier...
rem
rem Args from VisualSvn Server are ignored. Pass Bamboo BUILD KEY as the first
rem parameter to this script.
Powershell.exe -executionpolicy remotesigned -File C:\SvnHooks\BambooWebApiTrigger.ps1 -key %1
BambooWebApiTrigger.ps1
A PowerShell script to run System.Net.WebClient, also in C:\SvnHooks\. Overwrite bamboo.yourdefaultdomain.com with your local Bamboo server:
# A Powershell script to trigger Bamboo to build a specific key
param (
[string]$baseurl = "http://bamboo.radicalsystems.com.au:8085",
[Parameter(Mandatory=$true)]
[string]$key,
[string]$tmp = $null
)
$fullUrl = $baseurl + "/updateAndBuild.action?buildKey=" + $key
if (!$tmp) {
$tmp = [io.path]::GetTempFileName()
}
echo "Pinging Bamboo API at '$fullUrl'"
$client = new-object System.Net.WebClient
$client.DownloadFile($fullUrl, $tmp)
# comment Remove-Item to see the results. It is a HTML result with success message.
# echo "Results are in $tmp"
Remove-Item $tmp
Configure VisualSvn
Right click on project in VisualSvn Server Manager > Properties > Hooks > Post-commit hook (Edit).
Enter this line after any others:
C:\SvnHooks\BambooWebApiTrigger.bat BambooProjectKey
where BambooProjectKey is the key, found after your bamboo url when browsing the Build Plan (not the project). It usually has a hyphen in it: http://bamboo.yourdomain.com:8085/browse/FOO-BAR. In this case, FOO-BAR would be the key.
Configure Bamboo
Change your Bamboo trigger to Repository triggers the build when changes are committed
Options
You can overwrite the key from the VisualSvn post-commit hook dialog, as well as Bamboo base URL and temp file location from the batch file runner.