Skip to content

Instantly share code, notes, and snippets.

@bjcull
Forked from dennisroche/Install-Seq.ps1
Last active June 21, 2023 06:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save bjcull/d566d237ed172ae9c524bc289c41eda9 to your computer and use it in GitHub Desktop.
Save bjcull/d566d237ed172ae9c524bc289c41eda9 to your computer and use it in GitHub Desktop.
Download and install Seq (https://getseq.net/). Can be used by Azure Resource Manager template. Use RawGit to access the file with proper Content-Type headers - https://rawgit.com/
[CmdletBinding()]
param (
[string]$SeqVersion,
[string]$SeqPort
)
$installBasePath = "C:\Install\"
$global:seqDataPath = "C:\ProgramData\Seq"
function Write-Log
{
param (
[string] $message
)
$timestamp = ([System.DateTime]::UTCNow).ToString("yyyy'-'MM'-'dd'T'HH':'mm':'ss")
Write-Output "[$timestamp] $message"
}
function Add-InstallLocation
{
Write-Log "======================================"
Write-Log " Create Install Location"
Write-Log ""
if (!(Test-Path $installBasePath))
{
Write-Log "Creating installation folder at '$installBasePath' ..."
New-Item -ItemType Directory -Path $installBasePath | Out-Null
Write-Log "done."
}
else
{
Write-Log "Installation folder at '$installBasePath' already exists."
}
Write-Log ""
}
function Add-DataDisk
{
Write-Log "======================================"
Write-Log " Create Data Disk"
Write-Log ""
$driveLetters = @('F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z')
$allocateDriveLetters = (Get-Partition).DriveLetter
$availableDriveLetters = $driveLetters |? {$_ -notin $allocateDriveLetters }
$disk = (Get-Disk |? { $_.PartitionStyle -eq 'RAW' })[0]
Write-Log "Found attached data disk with RAW partition."
$driveLetter = $availableDriveLetters[0].ToString()
Write-Log "Assigning drive letter $driveLetter."
Write-Log "Formatting ..."
$disk | Initialize-Disk -PartitionStyle MBR -PassThru | New-Partition -UseMaximumSize -DriveLetter $driveLetter | Format-Volume -FileSystem NTFS -NewFileSystemLabel "Seq-DataDisk" -Confirm:$false -Force | Out-Null
Write-Log "done."
$path = $driveLetter + ':\SeqData'
Write-Log "Creating '$path' ..."
New-Item -Path $path -ItemType Directory | Out-Null
$global:seqDataPath = $path
Write-Log "done."
Write-Log "done."
Write-Log ""
}
function Install-Seq
{
$msiFileName = "Seq-$SeqVersion.msi"
$downloadUrl = "https://getseq.net/Download/Begin?version=$SeqVersion"
$msiPath = $installBasePath + $msiFileName
$msiLogPath = $installBasePath + $msiFileName + '.log'
$installerLogPath = $installBasePath + 'Install-Seq.ps1.log'
Write-Log "======================================"
Write-Log " Install Seq"
Write-Log ""
Write-Log "Downloading Seq installer '$downloadUrl' to '$msiPath' ..."
[System.Net.ServicePointManager]::SecurityProtocol = [System.Net.SecurityProtocolType]::Tls12
Invoke-WebRequest -Uri $downloadUrl -Method GET -OutFile $msiPath
Write-Log "done."
Write-Log "Installing via '$msiPath' ..."
$exe = 'msiexec.exe'
$args = @(
'/qn',
'/i', $msiPath,
'/l*v', $msiLogPath
)
$output = .$exe $args
$output | %{ Write-Log "$_" }
Write-Log "done."
Write-Log ""
}
function Set-SeqConfiguration
{
Write-Log "======================================"
Write-Log " Configure Seq"
Write-Log ""
$exe = 'C:\Program Files\Seq\Seq.exe'
$count = 0
while(!(Test-Path $exe) -and $count -lt 5)
{
Write-Log "$exe - not available yet ... waiting 10s ..."
Start-Sleep -s 10
$count = $count + 1
}
Write-Log "Configure and start Seq instance ..."
$args = @(
"install",
"--listen=http://localhost:$SeqPort",
"--storage=$global:seqDataPath"
)
$output = .$exe $args
$output | %{ Write-Log "$_" }
Write-Log "done."
Write-Log ""
}
function Set-ConfigureFirewall
{
Write-Log "======================================"
Write-Log " Configure Firewall"
Write-Log ""
$firewallRuleName = "Allow_Port$($SeqPort)_HTTP"
if ((Get-NetFirewallRule -Name $firewallRuleName -ErrorAction Ignore) -eq $null)
{
Write-Log "Creating firewall rule to allow port $SeqPort HTTP traffic ..."
$firewallRule = @{
Name=$firewallRuleName
DisplayName ="Allow Port $SeqPort (HTTP)"
Description="Port $SeqPort for HTTP traffic"
Direction='Inbound'
Protocol='TCP'
LocalPort=([int]$SeqPort)
Enabled='True'
Profile='Any'
Action='Allow'
}
New-NetFirewallRule @firewallRule | %{ Write-Log "$_" }
Write-Log "done."
}
else
{
Write-Log "Firewall rule to allow port $SeqPort HTTP traffic already exists."
}
Write-Log ""
}
try
{
Write-Log "======================================"
Write-Log " Installing Seq"
Write-Log "======================================"
Write-Log ""
Add-DataDisk
Add-InstallLocation
Install-Seq
Set-SeqConfiguration
Set-ConfigureFirewall
Write-Log "Installation successful."
Write-Log ""
}
catch
{
Write-Log $_
}
Restart-Computer
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment