Export (0) Print
Expand All
Collapse the table of content
Expand the table of content
Expand Minimize

New-Service

Updated: August 9, 2015

New-Service

Creates a new Windows service.

Syntax

Parameter Set: Default
New-Service [-Name] <String> [-BinaryPathName] <String> [-Credential <PSCredential> ] [-DependsOn <String[]> ] [-Description <String> ] [-DisplayName <String> ] [-StartupType <ServiceStartMode> {Boot | System | Automatic | Manual | Disabled} ] [-Confirm] [-WhatIf] [ <CommonParameters>]




Detailed Description

The New-Service cmdlet creates a new entry for a Windows service in the registry and in the service database. A new service requires an executable file that runs during the service.

The parameters of this cmdlet let you set the display name, description, startup type, and dependencies of the service.

Parameters

-BinaryPathName<String>

Specifies the path of the executable file for the service. This parameter is required.


Aliases

none

Required?

true

Position?

2

Default Value

none

Accept Pipeline Input?

false

Accept Wildcard Characters?

false

-Credential<PSCredential>

Specifies a user account that has permission to perform this action.

Type a user name, such as User01 or Domain01\User01, or enter a PSCredential object, such as one generated by the Get-Credential cmdlet. If you type a user name, this cmdlet prompts you for a password.


Aliases

none

Required?

false

Position?

named

Default Value

none

Accept Pipeline Input?

false

Accept Wildcard Characters?

false

-DependsOn<String[]>

Specifies the names of other services upon which the new service depends. To enter multiple service names, use a comma to separate the names.


Aliases

none

Required?

false

Position?

named

Default Value

None

Accept Pipeline Input?

false

Accept Wildcard Characters?

false

-Description<String>

Specifies a description of the service.


Aliases

none

Required?

false

Position?

named

Default Value

none

Accept Pipeline Input?

false

Accept Wildcard Characters?

false

-DisplayName<String>

Specifies a display name for the service.


Aliases

none

Required?

false

Position?

named

Default Value

none

Accept Pipeline Input?

false

Accept Wildcard Characters?

false

-Name<String>

Specifies the name of the service. This parameter is required.


Aliases

ServiceName

Required?

true

Position?

1

Default Value

none

Accept Pipeline Input?

false

Accept Wildcard Characters?

false

-StartupType<ServiceStartMode>

Sets the startup type of the service. The acceptable values for this parameter are:

-- Manual. The service is started only manually, by a user, using the Service Control Manager, or by an application.
-- Automatic. The service is started or was started by the operating system, at system start-up. If an automatically started service depends on a manually started service, the manually started service is also started automatically at system startup.
-- Disabled. The service is disabled and cannot be started by a user or application.

The default value is Automatic.


Aliases

none

Required?

false

Position?

named

Default Value

none

Accept Pipeline Input?

false

Accept Wildcard Characters?

false

-Confirm

Prompts you for confirmation before running the cmdlet.


Required?

false

Position?

named

Default Value

false

Accept Pipeline Input?

false

Accept Wildcard Characters?

false

-WhatIf

Shows what would happen if the cmdlet runs. The cmdlet is not run.


Required?

false

Position?

named

Default Value

false

Accept Pipeline Input?

false

Accept Wildcard Characters?

false

<CommonParameters>

This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see    about_CommonParameters.

Inputs

The input type is the type of the objects that you can pipe to the cmdlet.

  • None

    You cannot pipe input to this cmdlet.


Outputs

The output type is the type of the objects that the cmdlet emits.

  • System.ServiceProcess.ServiceController

    This cmdlet returns an object that represents the new service.


Notes

  • To run this cmdlet on Windows Vista and later versions of the Windows operating system, start Windows PowerShell by using the Run as administrator option.

  • To delete a service, use Sc.exe, or use the Get-WmiObject cmdlet to get the Win32_Service object that represents the service and then use the Delete method to delete the service. The object that Get-Service returns does not have a delete method.

Examples

Example 1: Create a service

This command creates a service named TestService.


PS C:\> New-Service -Name "TestService" -BinaryPathName "C:\WINDOWS\System32\svchost.exe -k netsvcs"

Example 2: Create a service that includes description, startup type, and display name

This command creates a service named TestService. It uses the parameters of New-Service to specify a description, startup type, and display name for the new service.


PS C:\> New-Service -Name "TestService" -BinaryPathName "C:\WINDOWS\System32\svchost.exe -k netsvcs" -DependsOn NetLogon -DisplayName "Test Service" -StartupType Manual -Description "This is a test service."

Example 3: View the new service

This command uses Get-WmiObject to get the Win32_Service object for the new service. This object includes the start mode and the service description.


PS C:\> Get-WmiObject win32_service -Filter "name='testservice'"

Example 4: Delete a service

This example shows two ways to delete the TestService service. The first command uses the delete option of Sc.exe. The second command uses the Delete method of the Win32_Service objects that Get-WmiObject returns.


PS C:\> sc.exe delete TestService
- or -
PS C:\> (Get-WmiObject win32_service -Filter "name='TestService'").delete()

Related topics

Community Additions

ADD
Show:
© 2016 Microsoft