Red Gate forums :: View topic - Windows Services
Return to www.red-gate.com RSS Feed Available

Search  | Usergroups |  Profile |  Messages |  Log in  Register 
Go to product documentation

Deployment Manager PowerShell Scripts forum

Windows Services

Search in Deployment Manager PowerShell Scripts forum
Post new topic   Reply to topic
Jump to:  
Author Message
justin.caldicott



Joined: 20 Apr 2011
Posts: 55

PostPosted: Fri Dec 14, 2012 3:57 pm    Post subject: Windows Services Reply with quote

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:

# 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:

$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
Back to top
View user's profile Send private message
siesquen



Joined: 31 Jul 2013
Posts: 2

PostPosted: Wed Jul 31, 2013 6:28 pm    Post subject: Re: Windows Services Reply with quote

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:

# 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:

$NetFrameworkDirectory = $([System.Runtime.InteropServices.RuntimeEnvironment]::GetRuntimeDirectory())
& (Join-Path $NetFrameworkDirectory "InstallUtil.exe") "path\to\my.dll" | Write-Host
Smile
Back to top
View user's profile Send private message
siesquen



Joined: 31 Jul 2013
Posts: 2

PostPosted: Wed Jul 31, 2013 6:30 pm    Post subject: Re: Windows Services Reply with quote

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:

# 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:

$NetFrameworkDirectory = $([System.Runtime.InteropServices.RuntimeEnvironment]::GetRuntimeDirectory())
& (Join-Path $NetFrameworkDirectory "InstallUtil.exe") "path\to\my.dll" | Write-Host
Back to top
View user's profile Send private message
justin.caldicott



Joined: 20 Apr 2011
Posts: 55

PostPosted: Mon Aug 05, 2013 12:13 pm    Post subject: Reply with quote

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/display/DM2/Creating+packages
http://documentation.red-gate.com/display/DM2/Using+PowerShell+scripts+in+deployment

Best wishes,
_________________
Justin Caldicott
Product Manager - Deployment Manager
Red Gate
Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic All times are GMT + 1 Hour
Page 1 of 1

 
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group