Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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