Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
param([string] $Version, [string] $StorageAccount, [string] $StorageUser, [string] $StoragePassword)
$ErrorActionPreference = "Stop"
Set-StrictMode -Version Latest;
New-Item -ItemType Directory -Force -Path C:\Temp
function Log($Message)
$timestamp = Get-Date -Format "yyyy-MM-dd HH:mm:ss,fff"
$newLine = [System.Environment]::NewLine
$logEntry = "$timestamp $Message $newLine"
Write-Host $logEntry
Add-Content -Path "C:\Temp\Log.txt" -Value $logEntry
$installerName = "Octopus.$Version.msi"
$serverDownloadPath = "$Version-x64.msi"
function Download-File
param (
Log "Downloading $url to $saveAs"
$downloader = new-object System.Net.WebClient
$downloader.DownloadFile($url, $saveAs)
function Install-Server
Log "Beginning Octopus Server installation"
$pathspec = "$env:SystemDrive\\OctopusTest"
if(Test-Path -path $pathspec)
Remove-Item $pathspec -recurse -force
$serverDownloadSavePath = $ExecutionContext.SessionState.Path.GetUnresolvedProviderPathFromPSPath(".\\$installerName")
if ((test-path $serverDownloadSavePath) -ne $true)
Log "Downloading latest Octopus Server MSI from '$serverDownloadPath' to '$serverDownloadSavePath'..."
Download-File $serverDownloadPath $serverDownloadSavePath
Log "Skipping download of latest Octopus Server MSI as '$serverDownloadSavePath' already exists"
Log "Installing MSI"
$msiExitCode = (Start-Process -FilePath "msiexec.exe" -ArgumentList "/i $installerName /quiet /l*v C:\\ServerMsiInstallation.log" -Wait -Passthru).ExitCode
Log "Octopus Server MSI installer returned exit code $msiExitCode"
Log "Removing msi from '$serverDownloadSavePath'"
Remove-Item -Path $serverDownloadSavePath -Force
function Setup-VM
& netsh.exe firewall add portopening TCP 80 "Octopus Server"
& netsh.exe firewall add portopening TCP 443 "Octopus Server"
& netsh.exe firewall add rule name="Tentacles" dir=in action=allow protocol=TCP localport=10000-15000
$serverDownloadSavePath = $ExecutionContext.SessionState.Path.GetUnresolvedProviderPathFromPSPath(".\\")
if ((test-path $serverDownloadSavePath) -ne $true)
Log "Downloading tools '' to '$serverDownloadSavePath'..."
Download-File -url "" -saveAs $serverDownloadSavePath
$folder = $ExecutionContext.SessionState.Path.GetUnresolvedProviderPathFromPSPath(".\\PSTools")
Expand-Archive $serverDownloadSavePath -DestinationPath $folder
Log "Skipping downloading tools '$serverDownloadSavePath' already exists"
& .\PsTools\PsExec64.exe -accepteula -s cmdkey /add:$StorageAccount /user:$StorageUser /pass:$StoragePassword
Log "Octopus is not installed. Installing $Version"
Log "Server deployment finished"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment