Skip to content

Instantly share code, notes, and snippets.

@sitereactor
Created August 30, 2018 13:22
Show Gist options
  • Save sitereactor/dcf056722a6beb79b217087258a7b225 to your computer and use it in GitHub Desktop.
Save sitereactor/dcf056722a6beb79b217087258a7b225 to your computer and use it in GitHub Desktop.
Modified Powershell script for installing TopShelf-based Windows Services through Octopus Deploy. This script has been updated with an ArgumentList that works with username and password passed in from Variables.
$step = $OctopusParameters['Unpackage step']
$username = $OctopusParameters['Username'];
$password = $OctopusParameters['Password'];
$customExeFilename = $OctopusParameters['Exe filename'];
$outputPath = $OctopusParameters["Octopus.Action[$step].Package.CustomInstallationDirectory"]
if(!$outputPath)
{
$outputPath = $OctopusParameters["Octopus.Action[$step].Output.Package.InstallationDirectoryPath"]
}
$defaultExeFilename = $OctopusParameters["Octopus.Action[$step].Package.NuGetPackageId"] + ".exe"
$exeFilename = If ($customExeFilename) {$customExeFilename} Else {$defaultExeFilename}
$path = Join-Path $outputPath $exeFilename
if(-not (Test-Path $path) )
{
Throw "$path was not found"
}
Write-Host "Installing from: $path"
if(!$username)
{
Start-Process $path -ArgumentList "install" -NoNewWindow -Wait | Write-Host
}
else
{
Start-Process $path -ArgumentList "install -username `"$username`" -password `"$password`" " -NoNewWindow -Wait | Write-Host
}
Start-Process $path -ArgumentList "start" -NoNewWindow -Wait | Write-Host
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment