Skip to content

Instantly share code, notes, and snippets.

@sjwaight
Created July 31, 2017 00:19
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sjwaight/c59167101b8f7542856f70affc108d13 to your computer and use it in GitHub Desktop.
Save sjwaight/c59167101b8f7542856f70affc108d13 to your computer and use it in GitHub Desktop.
PowerShell script demonstrating how you can bootstrap a VM to install IIS, ASP.Net, Web Deploy and a custom ASP.Net solution
$workingFolder = "C:\temp\"
$packerFolder = "C:\DeployTemp\a\"
$webPIURL = "http://download.microsoft.com/download/C/F/F/CFF3A0B8-99D4-41A2-AE1A-496C08BEB904/WebPlatformInstaller_amd64_en-US.msi"
$webPIInstaller = $workingFolder + "WebPlatformInstaller_amd64_en-US.msi"
$webPIExec = $env:ProgramFiles + "\Microsoft\Web Platform Installer\WebPiCmd-x64.exe"
$webDeployPackage = $packerFolder + "MyWebsite.API.zip"
$webDeployParams = $packerFolder + "MyWebsite.API.SetParameters.xml"
# Create working directory
New-Item $workingFolder -Type Directory -Force
# Install IIS and ASP.Net 4.5
Add-WindowsFeature Web-Server, Web-Asp-Net45
# Download and install Web Platform Installer
Invoke-WebRequest $webPIURL -OutFile $webPIInstaller
# Install Web PI now downloaded
Start-Process msiexec.exe -ArgumentList "/i $webPIInstaller /quiet" -NoNewWindow -Wait
# Install the bits we need - main one is WebDeploy
Start-Process $webPIExec -ArgumentList "/install /products:ASPNET45,ASPNET_REGIIS_NET4,WDeploy /AcceptEula" -NoNewWindow -Wait
# Find out where Web Deploy is installed
$MSDeployPath = (Get-ChildItem "HKLM:\SOFTWARE\Microsoft\IIS Extensions\MSDeploy" | Select-Object -Last 1).GetValue("InstallPath") + "msdeploy.exe"
# Install the Web API using WebDeploy
cmd.exe /C $("`"{0}`" -verb:sync -source:package={1} -dest:auto,ComputerName=localhost -setParam:name='IIS Web Application Name',value='Default Web Site' -setParamFile:$webDeployParams 2> $workingFolder\err.log" -f $MSDeployPath, $webDeployPackage)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment