qbo4.WebServer.ps1
<#
Manage installation of IIS and WebDeploy to prepare a web or application server for qbo3 installation. #> function Install-qboWebServer { <# .SYNOPSIS Installs the IIS features qbo3 requires to run, using the ServerManager Powershell cmdlet 'Install-WindowsFeature'. This only works on Windows Server. .INPUTS features: Array of features required by qbo3. Only use this if you need to override the default value. #> [CmdletBinding()] Param( [Parameter(Position=0)] [string[]]$Features, [Parameter(Position=1)] [ValidateSet('3.6','4')] [string]$Version="4", [Parameter(Position=2)] [bool]$Force=$true ) Install-qboWebServerWindowsClient $Features Install-qboWebDeploy $Version $Force } function Install-qboWebServerWindowsServer { <# .SYNOPSIS Installs the IIS features qbo3 requires to run, using the ServerManager Powershell cmdlet 'Install-WindowsFeature'. This only works on Windows Server. .INPUTS features: Array of features required by qbo3. Only use this if you need to override the default value. #> [CmdletBinding()] Param( [Parameter(Position=0)] [string[]]$Features = @("Web-WebServer","Web-Common-Http","Web-Default-Doc","Web-Http-Errors","Web-Static-Content", "Web-Http-Redirect","Web-Health","Web-Http-Logging","Web-Custom-Logging","Web-Log-Libraries","Web-ODBC-Logging", "Web-Stat-Compression","Web-Dyn-Compression","Web-Security","Web-Basic-Auth","Web-CertProvider","Web-Cert-Auth", "Web-Url-Auth","Web-App-Dev","Web-Net-Ext","Web-Net-Ext45","Web-Asp-Net","Web-Asp-Net45","Web-ISAPI-Ext" ,"Web-ISAPI-Filter", "Web-Includes","Web-WebSockets","Web-Mgmt-Tools","Web-Scripting-Tools","Web-Mgmt-Service") ) Install-WindowsFeature -Name $Features } function Install-qboWebServerWindowsClient { <# .SYNOPSIS Installs the IIS features qbo3 requires to run, using the DSIM Powershell cmdlet 'Enable-WindowsOptionalFeature'. This works on Windows 10 (non-server machines). .INPUTS features: Array of features required by qbo3. Only use this if you need to override the default value. #> [CmdletBinding()] Param( [Parameter(Position=0)] [string[]]$Features = @("IIS-WebServerRole","IIS-WebServer","IIS-CommonHttpFeatures","IIS-HttpErrors","IIS-HttpRedirect", "IIS-ApplicationDevelopment","IIS-NetFxExtensibility","IIS-NetFxExtensibility45","IIS-HealthAndDiagnostics","IIS-HttpLogging", "IIS-LoggingLibraries","IIS-RequestMonitor","IIS-HttpTracing","IIS-Security","IIS-URLAuthorization","IIS-RequestFiltering", "IIS-IPSecurity","IIS-Performance","IIS-HttpCompressionDynamic","IIS-WebServerManagementTools","IIS-ManagementScriptingTools", "IIS-HostableWebCore","IIS-StaticContent","IIS-DefaultDocument","IIS-WebSockets","IIS-ASPNET","IIS-ASPNET45","IIS-CGI", "IIS-ISAPIExtensions","IIS-ISAPIFilter","IIS-ServerSideIncludes","IIS-CustomLogging","IIS-BasicAuthentication", "IIS-HttpCompressionStatic","IIS-ManagementConsole","IIS-ManagementService","IIS-CertProvider","IIS-WindowsAuthentication", "IIS-DigestAuthentication","IIS-ClientCertificateMappingAuthentication","IIS-IISCertificateMappingAuthentication", "IIS-ODBCLogging") ) foreach ($i in $Features) { $f = Get-WindowsOptionalFeature -online -FeatureName $i if ($f -eq $null) { Write-Warning("This machine does not appear to have the $i feature available.") } elseif ($f.State -eq 'Enabled') { Write-Verbose("Feature $i already enabled.") } else { Write-Verbose("Enabling feature $i.") Enable-WindowsOptionalFeature -online -FeatureName $i } } } function Install-qboWebDeploy { <# .SYNOPSIS Installs Web Deploy to enable publishing web packages to IIS. .INPUTS Version: Web Deploy version to install; either 3.6 or 4 Force: When true, reinstall WebDeploy even if already present. #> [CmdletBinding()] Param( [Parameter(Position=0)] [ValidateSet('3.6','4')] [string]$Version="4", [Parameter(Position=1)] [bool]$Force=$true ) $versions = @{ "3.6"="https://download.microsoft.com/download/0/1/D/01DC28EA-638C-4A22-A57B-4CEF97755C6C/WebDeploy_amd64_en-US.msi"; "4"="https://download.visualstudio.microsoft.com/download/pr/e1828da1-907a-46fe-a3cf-f3b9ea1c485c/035860f3c0d2bab0458e634685648385/webdeploy_amd64_en-us.msi" } $ms = get-service -name 'WMSvc' -erroraction SilentlyContinue if ($ms -eq $null) { Write-Warning "Web Management Service is not installed. Please run Install-qboWebServer to ensure it's installed." return $false } Write-Verbose "Starting Web Management Service" Start-Service -Name "WMSvc" $ds = get-service -name 'MsDepSvc' -erroraction SilentlyContinue if (($ds -eq $null) -or $Force) { $wdpath = "$($env:temp)\wdmsi.msi" Write-Verbose "Downloading WebDeploy msi from $($wdpath)" $wdmsi = $versions[$Version] Invoke-WebRequest $wdmsi -OutFile $wdpath Write-Verbose "Installing WebDeploy silently." $arguments = "/i `"$wdpath`" /qb ADDLOCAL=ALL /quiet " Start-Process msiexec.exe -ArgumentList $arguments -Wait } else { Write-Verbose "Start Web Deployment Agent Service." Start-Service -Name "MsDepSvc" } return $true } Export-ModuleMember -Function @('Install-qboWebServer', 'Install-qboWebDeploy') |