Skip to content

Instantly share code, notes, and snippets.

@sitereactor
Created August 30, 2018 13:22
Show Gist options
  • Save sitereactor/d9e265427b499519ccfd56c5aee31466 to your computer and use it in GitHub Desktop.
Save sitereactor/d9e265427b499519ccfd56c5aee31466 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
@sitereactor
Copy link
Author

Line 28 in the above script was changed from Start-Process $path -ArgumentList @("install", "-username", $username, "-password", $password) -NoNewWindow -Wait | Write-Host to what is there now:
Start-Process $path -ArgumentList "install -username "$username" -password "$password" " -NoNewWindow -Wait | Write-Host
and now it actually works. We can install a TopShelf Windows Service where we supply the username and password for the windows user that the service should be running as.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment