Skip to content

Instantly share code, notes, and snippets.

@russmckendrick
Last active August 4, 2021 08:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save russmckendrick/0555f4f39e38ff7e2e6a3ee43e91a884 to your computer and use it in GitHub Desktop.
Save russmckendrick/0555f4f39e38ff7e2e6a3ee43e91a884 to your computer and use it in GitHub Desktop.
configure-music-app.ps1
<#
.SYNOPSIS
Downloads and configures .Net Core Music Store application sample across IIS and Azure SQL DB.
#>
Param (
[string]$user,
[string]$password,
[string]$sqlserver,
[string]$database
)
# Force use of TLS 1.2
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
# Firewall
netsh advfirewall firewall add rule name="http" dir=in action=allow protocol=TCP localport=80
# Folders
New-Item -ItemType Directory c:\temp
New-Item -ItemType Directory c:\music
# Install iis
Install-WindowsFeature web-server -IncludeManagementTools
# Install dot.net core sdk
Invoke-WebRequest http://go.microsoft.com/fwlink/?LinkID=615460 -outfile c:\temp\vc_redistx64.exe
Start-Process c:\temp\vc_redistx64.exe -ArgumentList '/quiet' -Wait
Invoke-WebRequest https://go.microsoft.com/fwlink/?LinkID=809122 -outfile c:\temp\DotNetCore.1.0.0-SDK.Preview2-x64.exe
Start-Process c:\temp\DotNetCore.1.0.0-SDK.Preview2-x64.exe -ArgumentList '/quiet' -Wait
Invoke-WebRequest https://go.microsoft.com/fwlink/?LinkId=817246 -outfile c:\temp\DotNetCore.WindowsHosting.exe
Start-Process c:\temp\DotNetCore.WindowsHosting.exe -ArgumentList '/quiet' -Wait
# Download music app
Invoke-WebRequest https://github.com/Microsoft/dotnet-core-sample-templates/raw/master/dotnet-core-music-windows/music-app/music-store-azure-demo-pub.zip -OutFile c:\temp\musicstore.zip
Expand-Archive C:\temp\musicstore.zip c:\music
# Azure SQL connection sting in environment variable
[Environment]::SetEnvironmentVariable("Data:DefaultConnection:ConnectionString", "Server=$sqlserver;Database=$database;Integrated Security=False;User Id=$user;Password=$password;MultipleActiveResultSets=True;Connect Timeout=30",[EnvironmentVariableTarget]::Machine)
# Pre-create database
$env:Data:DefaultConnection:ConnectionString = "Server=$sqlserver;Database=$database;Integrated Security=False;User Id=$user;Password=$password;MultipleActiveResultSets=True;Connect Timeout=30"
Start-Process 'C:\Program Files\dotnet\dotnet.exe' -ArgumentList 'c:\music\MusicStore.dll'
# Configure iis
Remove-WebSite -Name "Default Web Site"
Set-ItemProperty IIS:\AppPools\DefaultAppPool\ managedRuntimeVersion ""
New-Website -Name "MusicStore" -Port 80 -PhysicalPath C:\music\ -ApplicationPool DefaultAppPool
& iisreset
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment