PowerShell Logo Small

New-Service



This is the built-in help made by Microsoft for the command 'New-Service', in PowerShell version 3 - as retrieved from Windows version 'Microsoft Windows Server 2012 Standard' PowerShell help files on 2016-06-23.

For PowerShell version 3 and up, where you have Update-Help, this command was run just before creating the web pages from the help files.

SYNOPSIS

Creates a new Windows service.

SYNTAX


New-Service [-Name] <String> [-BinaryPathName] <String> [-Credential <PSCredential>] [-DependsOn <String[]>] [-Description <String>]
[-DisplayName <String>] [-StartupType <ServiceStartMode>] [<CommonParameters>]



Search powershellhelp.space

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 executes during the service.


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



<

RELATED LINKS

Online Version: http://go.microsoft.com/fwlink/?LinkID=113359
Get-Service
Restart-Service
Resume-Service
Set-Service
Start-Service
Stop-Service
Suspend-Service

REMARKS

<

Examples


-------------------------- EXAMPLE 1 --------------------------

PS C:\>new-service -name TestService -binaryPathName "C:\WINDOWS\System32\svchost.exe -k netsvcs"



This command creates a new service named "TestService".








-------------------------- EXAMPLE 2 --------------------------

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."



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








-------------------------- EXAMPLE 3 --------------------------

PS C:\>get-wmiobject win32_service -filter "name='testservice'"
ExitCode : 0
Name : testservice
ProcessId : 0
StartMode : Auto
State : Stopped
Status : OK



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








-------------------------- EXAMPLE 4 --------------------------

PS C:\>sc.exe delete TestService
- or -
PS C:\>(get-wmiobject win32_service -filter "name='TestService'").delete()



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 the Get-WmiObject cmdlet returns.