Windows Services

Share your PowerShell scripts for Deployment Manager

Moderators: Mike Upton, justin.caldicott, csmith, chirayu, DavidSimner

Windows Services

Postby justin.caldicott » Fri Dec 14, 2012 3:57 pm

This script uses the Service Control tool (sc.exe) to create or update a Windows Service. It assumes some variables have been set in the Deployment Manager web interface:

Code: Select all
# These variables should be set via the Deployment Manager web interface:
#
# ServiceName - Name of the Windows service
# ServiceExecutable - Path to the .exe containing the service
#
# sc.exe is the Service Control utility in Windows
$service = Get-Service $ServiceName -ErrorAction SilentlyContinue
$fullPath = Resolve-Path $ServiceExecutable
if (! $service)
{
  Write-Host \"The service will be installed\"
  New-Service -Name $ServiceName -BinaryPathName $fullPath -StartupType Automatic
}
else
{
  Write-Host \"The service will be stopped and reconfigured\"
  Stop-Service $ServiceName -Force
  & \"sc.exe\" config $service.Name binPath= $fullPath start= auto | Write-Host
}
Write-Host \"Starting the service\"
Start-Service $ServiceName


This script uses InstallUtil.exe to install custom Event Log sources and Windows Services:

Code: Select all
$NetFrameworkDirectory = $([System.Runtime.InteropServices.RuntimeEnvironment]::GetRuntimeDirectory())
& (Join-Path $NetFrameworkDirectory \"InstallUtil.exe\") \"path\\to\\my.dll\" | Write-Host
Justin Caldicott
Product Manager - Deployment Manager
Red Gate
justin.caldicott
 
Posts: 55
Joined: Wed Apr 20, 2011 5:42 pm

Re: Windows Services

Postby siesquen » Wed Jul 31, 2013 6:28 pm

Hi,

This first time that i work with your solutions. Is evaluating Deployment Manager now, but now need know how work others requirements...

For example, I have 3 environments where should sync Windows Services and Task. I can syn with PowerShell Scripts only?


Sorry for me bad english...

Regards,





justin.caldicott wrote:This script uses the Service Control tool (sc.exe) to create or update a Windows Service. It assumes some variables have been set in the Deployment Manager web interface:

Code: Select all
# These variables should be set via the Deployment Manager web interface:
#
# ServiceName - Name of the Windows service
# ServiceExecutable - Path to the .exe containing the service
#
# sc.exe is the Service Control utility in Windows
$service = Get-Service $ServiceName -ErrorAction SilentlyContinue
$fullPath = Resolve-Path $ServiceExecutable
if (! $service)
{
  Write-Host "The service will be installed"
  New-Service -Name $ServiceName -BinaryPathName $fullPath -StartupType Automatic
}
else
{
  Write-Host "The service will be stopped and reconfigured"
  Stop-Service $ServiceName -Force
  & "sc.exe" config $service.Name binPath= $fullPath start= auto | Write-Host
}
Write-Host "Starting the service"
Start-Service $ServiceName


This script uses InstallUtil.exe to install custom Event Log sources and Windows Services:

Code: Select all
$NetFrameworkDirectory = $([System.Runtime.InteropServices.RuntimeEnvironment]::GetRuntimeDirectory())
& (Join-Path $NetFrameworkDirectory "InstallUtil.exe") "path\\to\\my.dll" | Write-Host
:)
siesquen
 
Posts: 2
Joined: Wed Jul 31, 2013 6:07 pm

Re: Windows Services

Postby siesquen » Wed Jul 31, 2013 6:30 pm

How execute this scripts? I've never worked with these script types...


Regards,

justin.caldicott wrote:This script uses the Service Control tool (sc.exe) to create or update a Windows Service. It assumes some variables have been set in the Deployment Manager web interface:

Code: Select all
# These variables should be set via the Deployment Manager web interface:
#
# ServiceName - Name of the Windows service
# ServiceExecutable - Path to the .exe containing the service
#
# sc.exe is the Service Control utility in Windows
$service = Get-Service $ServiceName -ErrorAction SilentlyContinue
$fullPath = Resolve-Path $ServiceExecutable
if (! $service)
{
  Write-Host "The service will be installed"
  New-Service -Name $ServiceName -BinaryPathName $fullPath -StartupType Automatic
}
else
{
  Write-Host "The service will be stopped and reconfigured"
  Stop-Service $ServiceName -Force
  & "sc.exe" config $service.Name binPath= $fullPath start= auto | Write-Host
}
Write-Host "Starting the service"
Start-Service $ServiceName


This script uses InstallUtil.exe to install custom Event Log sources and Windows Services:

Code: Select all
$NetFrameworkDirectory = $([System.Runtime.InteropServices.RuntimeEnvironment]::GetRuntimeDirectory())
& (Join-Path $NetFrameworkDirectory "InstallUtil.exe") "path\\to\\my.dll" | Write-Host
siesquen
 
Posts: 2
Joined: Wed Jul 31, 2013 6:07 pm

Postby justin.caldicott » Mon Aug 05, 2013 12:13 pm

Hi,

You need to create a package that you want to deploy, and publish this to Deployment Manager. The PowerShell then goes into a file called Deploy.ps1, in the root of package.

Be sure to also specify the required variables in Deployment Manager. For this script, they are:
- ServiceName - Name of the Windows service.
- ServiceExecutable. Path to the .exe containing the service.

Please have a look at these sections of the documentation for details:
http://documentation.red-gate.com/displ ... g+packages
http://documentation.red-gate.com/displ ... deployment

Best wishes,
Justin Caldicott
Product Manager - Deployment Manager
Red Gate
justin.caldicott
 
Posts: 55
Joined: Wed Apr 20, 2011 5:42 pm


Return to Deployment Manager PowerShell Scripts

Who is online

Users browsing this forum: No registered users and 1 guest