user20358
user20358

Reputation: 14746

AWS creating a Windows server 2016 with software installation

I am trying to bring up a Windows Server 2016 with certain software installed by calling some powershell scripts in the User Data section of the configuration when using the console. I am trying to install IIS, a codedeploy agent,dotnet-hosting and dotnet core sdk. This is the script I have

<powershell>  
mkdir install-tools
Install-WindowsFeature Web-Server -IncludeManagementTools
powershell.exe -Command Read-S3Object -BucketName aws-codedeploy-us-east-1/latest -Key codedeploy-agent.msi -File c:\install-tools\codedeploy-agent.msi
Start-Process -Wait -FilePath c:\install-tools\codedeploy-agent.msi -WindowStyle Hidden
powershell -command "& { iwr https://download.visualstudio.microsoft.com/download/pr/bf608208-38aa-4a40-9b71-ae3b251e110a/bc1cecb14f75cc83dcd4bbc3309f7086/dotnet-hosting-3.0.0-win.exe -OutFile  c:\install-tools\dotnet-hosting-3.0.0-win.exe  } "
Start-Process -Wait -FilePath c:\install-tools\dotnet-hosting-3.0.0-win.exe  -WindowStyle Hidden
powershell -command "& { iwr https://download.visualstudio.microsoft.com/download/pr/40c1dd82-671c-4974-919d-ac8a61ef5a91/49ab67c335878f4a5bdd84e14c76708f/dotnet-sdk-2.2.402-win-x64.exe -OutFile  c:\install-tools\dotnet-sdk-2.2.402-win-x64.exe  } "
Start-Process -Wait -FilePath c:\install-tools\dotnet-sdk-2.2.402-win-x64.exe  -WindowStyle Hidden 
</powershell>  

After the instance starts up, it looks like all the commands in the script above get executed till the point where I try to install dotnet hosting at this line Start-Process -Wait -FilePath c:\install-tools\dotnet-hosting-3.0.0-win.exe -WindowStyle Hidden It seems like this line fails and the lines after that don't execute. Why is this this line failing?

Upvotes: 1

Views: 210

Answers (1)

Olaf Reitz
Olaf Reitz

Reputation: 694

You are just starting the .exe file without telling it what it needs to do. If you start these commands without the -WindowStyle Hidden you will see that you just started the installer most likely waiting that someone presses the Next/Intall Buttons.

Depending on the Installer they could have some arguments like /quit, /q, /silent or anything like that.

Start-Process uses -ArgumentList start the process with these arguments.

Start-Process -Wait -FilePath c:\install-tools\dotnet-hosting-3.0.0-win.exe -ArgumentList "/quit"  -WindowStyle Hidden

For most setup files that allow for argument based installations they have a /help and/or /? argument that will give you the basic information. For both of your .exe files that should be (untested)

/install /quiet /log $PathToInstallLogFile

Whereas the /install part is most likely unnecessary as it is normally the default value and /log is for debugging purpose.

Upvotes: 3

Related Questions