Skip to content

Instantly share code, notes, and snippets.

@sjwaight
Last active October 4, 2016 11:00
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save sjwaight/f9d51fee95c7b2fb4ce298d54f475884 to your computer and use it in GitHub Desktop.
Configuration Main
{
Import-DscResource –ModuleName 'PSDesiredStateConfiguration'
Node ('localhost')
{
Script DeployWindowsService
{
GetScript = {
@{
Result = ""
}
}
TestScript = {
$false
}
SetScript = {
$serviceName = "ResponseProcessor"
$displayName = "Simon Demonstration Response Processor"
# location where our AzureVMs File Copy RM Task copies our build outputs
$sourceLocation = "C:\temp\*"
$destinationLocation = "C:\Program Files\Simon\PaymentProcessorService\"
$binaryName = $destinationLocation + "Simon.Demo.ClearanceProcessor.exe"
$serviceDef = Get-Service -Name $serviceName -ErrorAction SilentlyContinue
If ($serviceDef -eq $null)
{
# first install - create directory
New-Item $destinationLocation -ItemType directory
Copy-Item $sourceLocation $destinationLocation -Force
New-Service -Name $serviceName -StartupType Automatic -DisplayName $displayName -BinaryPathName $binaryName
}
else
{
# has already been installed
if($serviceDef.Status -eq "Running")
{
Stop-Service -Name $serviceName
}
Copy-Item $sourceLocation $destinationLocation -Force
}
Start-Service -Name $serviceName
}
}
}
}
Main
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment