Created
August 30, 2018 13:22
-
-
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$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
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.