---
title: "Ensure Service"
---
Ensures the configuration of a Windows service on a server.
Ensure-Service(
	Name: <text>,
	[DisplayName: <text>],
	[Description: <text>],
	[Status: <integer>],
	[Exists: <true/false>],
	Path: <text>,
	[Startup: <integer>],
	[DelayedStart: <true/false>],
	[Credentials: <text>],
	[UserName: <text>],
	[Password: <text>],
	[FirstFailure: <integer>],
	[SecondFailure: <integer>],
	[SubsequentFailures: <integer>],
	[RestartDelay: <integer>],
	[OnFailureProgramPath: <text>],
	[RebootMessage: <text>],
	[Dependencies: <@(text)>],
	[StatusChangeTimeout: <TimeSpan>]
);
This operation may be prefixed with Windows::, although this is a built-in namespace and isn't really necessary.
| Name | Format | Script Usage | Usage Notes | 
|---|---|---|---|
| ☆ Name | text | Name | This argument is required. | 
| Display name | text | DisplayName | |
| Description | text | Description | |
| Status | integer | Status | |
| Exists | true/false | Exists | Default value is "True". | 
| ☆ Path w/ arguments | text | Path | The executable path of the service. This field may include any arguments that will be supplied to the executable. Executable paths that include spaces should be wrapped with double-quotes, e.g.: "C:\Program Files\Hdars\Hdars.Service.exe" -arg1 -arg2. This argument is required. | 
| Startup | integer | Startup | Startup type. | 
| DelayedStart | true/false | DelayedStart | Delayed start. | 
| Credentials | text | Credentials | The credential name to use as the service's Log On user. If a credential name is specified, the username and password fields will be ignored. | 
| User name | text | UserName | The user account name to run the service as. If this value is not supplied, NT AUTHORITY\LocalSystem will be assumed. | 
| Password | text | Password | The password for the account that runs the service. If NT AUTHORITY\LocalSystem is specified, this field must not have a value set. | 
| First failure | integer | FirstFailure | |
| Second failure | integer | SecondFailure | |
| Subsequent failures | integer | SubsequentFailures | |
| Restart delay | integer | RestartDelay | |
| Run program | text | OnFailureProgramPath | |
| Reboot message | text | RebootMessage | |
| Dependencies | @(text) | Dependencies | |
| Status change timeout | TimeSpan | StatusChangeTimeout | The number of seconds to wait for a server to change between two statuses (e.g. stopped to starting) before raising an error. Default value is "30". | 
# ensures the HdarsSvc is present on the server using the HdarsSvc credentials in Otter
Windows::Ensure-Service
(
    Name: HdarsSvc,
    DisplayName: HDARS Console Log Service,
    Status: Running,
    Path: E:\Services\Hdars.Service.exe,
    Startup: Auto,
    Credentials: HdarsSvc,
    FirstFailure: Restart
);