Skip to content

Instantly share code, notes, and snippets.

@andreasohlund
Created August 27, 2013 18:34
Show Gist options
  • Select an option

  • Save andreasohlund/6357270 to your computer and use it in GitHub Desktop.

Select an option

Save andreasohlund/6357270 to your computer and use it in GitHub Desktop.
$service = Get-Service "the service" -ErrorAction SilentlyContinue
if ($service)
{
"Backend service is already installed, going to uninstall first"
#get the path to the current service
$servicePath = "HKLM:SYSTEM\CurrentControlSet\Services\$service"
$serviceKey = get-itemproperty -path $servicePath -ErrorAction silentlycontinue
$imagePath = $serviceKey.psobject.properties | ?{ $_.Name -eq 'ImagePath' }
$pos = $imagePath.value.IndexOf("NServiceBus.Host.exe") + 22
$uninstallCommand = $imagePath.value.Substring(0, $pos).Replace('"','') + " /uninstall /endpointName:+$service /serviceName:$service"
"Uninstalling the previous service: " + $uninstallCommand
iex $uninstallCommand | Write-Host
}
"The service will be installed"
.\NServiceBus.Host.exe /install /endpointName:$service /serviceName:$service | Write-Host
"The service installed, will set recovery options"
sc.exe failure $service reset= 86400 actions= restart/120000/restart/120000/restart/120000
"Deploy completed successfully"
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment