| external help file | Microsoft.PowerShell.Commands.Management.dll-Help.xml |
|---|---|
| Locale | en-US |
| Module Name | Microsoft.PowerShell.Management |
| ms.date | 02/04/2026 |
| online version | https://learn.microsoft.com/powershell/module/microsoft.powershell.management/new-service?view=powershell-7.4&WT.mc_id=ps-gethelp |
| schema | 2.0.0 |
| title | New-Service |
Creates a new Windows service.
New-Service [-Name] <String> [-BinaryPathName] <String> [-DisplayName <String>] [-Description <String>]
[-SecurityDescriptorSddl <String>] [-StartupType <ServiceStartupType>] [-Credential <PSCredential>]
[-DependsOn <String[]>] [-WhatIf] [-Confirm] [<CommonParameters>]
This cmdlet is only available on the Windows platform.
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.
New-Service -Name "TestService" -BinaryPathName 'C:\WINDOWS\System32\svchost.exe -k netsvcs'This command creates a service named TestService.
$params = @{
Name = "TestService"
BinaryPathName = 'C:\WINDOWS\System32\svchost.exe -k netsvcs'
DependsOn = "NetLogon"
DisplayName = "Test Service"
StartupType = "Manual"
Description = "This is a test service."
}
New-Service @paramsThis 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.
Get-CimInstance -ClassName Win32_Service -Filter "Name='testservice'"ExitCode : 0
Name : testservice
ProcessId : 0
StartMode : Auto
State : Stopped
Status : OK
This command uses Get-CimInstance to get the Win32_Service object for the new service. This
object includes the start mode and the service description.
This example adds the SecurityDescriptor of the service being created.
$SDDL = "D:(A;;CCLCSWRPWPDTLOCRRC;;;SY)(A;;CCDCLCSWRPWPDTLOCRSDRCWDWO;;;BA)(A;;CCLCSWLOCRRC;;;SU)"
$params = @{
BinaryPathName = 'C:\WINDOWS\System32\svchost.exe -k netsvcs'
DependsOn = "NetLogon"
DisplayName = "Test Service"
StartupType = "Manual"
Description = "This is a test service."
SecurityDescriptorSddl = $SDDL
}
New-Service @paramsThe SecurityDescriptor is stored in the $SDDLToSet variable. The SecurityDescriptorSddl
parameter uses $SDDL to set the SecurityDescriptor of the new service.
Specifies the path of the executable file for the service. This parameter is required.
The fully qualified path to the service binary file. If the path contains a space, it must be quoted
so that it is correctly interpreted. For example, D:\my share\myservice.exe should be specified as
'"D:\my share\myservice.exe"'.
The path can also include arguments for an auto-start service. For example,
'"D:\my share\myservice.exe" arg1 arg2'. These arguments are passed to the service entry point.
For more information, see the lpBinaryPathName parameter of CreateServiceW API.
Type: System.String
Parameter Sets: (All)
Aliases: Path
Required: True
Position: 1
Default value: None
Accept pipeline input: False
Accept wildcard characters: FalseSpecifies the account used by the service as the Service Logon Account.
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.
Credentials are stored in a PSCredential object and the password is stored as a SecureString.
Note
For more information about SecureString data protection, see How secure is SecureString?.
Type: System.Management.Automation.PSCredential
Parameter Sets: (All)
Aliases:
Required: False
Position: Named
Default value: None
Accept pipeline input: False
Accept wildcard characters: FalseSpecifies the names of other services upon which the new service depends. To enter multiple service names, use a comma to separate the names.
Type: System.String[]
Parameter Sets: (All)
Aliases:
Required: False
Position: Named
Default value: None
Accept pipeline input: False
Accept wildcard characters: FalseSpecifies a description of the service.
Type: System.String
Parameter Sets: (All)
Aliases:
Required: False
Position: Named
Default value: None
Accept pipeline input: False
Accept wildcard characters: FalseSpecifies a display name for the service.
Type: System.String
Parameter Sets: (All)
Aliases:
Required: False
Position: Named
Default value: None
Accept pipeline input: False
Accept wildcard characters: FalseSpecifies the name of the service. This parameter is required.
Type: System.String
Parameter Sets: (All)
Aliases: ServiceName
Required: True
Position: 0
Default value: None
Accept pipeline input: False
Accept wildcard characters: FalseSpecifies the SecurityDescriptor for the service in Sddl format.
Type: System.String
Parameter Sets: (All)
Aliases: sd
Required: False
Position: Named
Default value: None
Accept pipeline input: False
Accept wildcard characters: FalseSets the startup type of the service. The acceptable values for this parameter are:
- 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.
- AutomaticDelayedStart - Starts shortly after the system boots.
- Disabled - The service is disabled and cannot be started by a user or application.
- InvalidValue - This value is not supported. Using this value results in an error.
- Manual - The service is started only manually, by a user, using the Service Control Manager, or by an application.
The default value is Automatic.
Type: Microsoft.PowerShell.Commands.ServiceStartupType
Parameter Sets: (All)
Aliases:
Accepted values: Automatic, Manual, Disabled, AutomaticDelayedStart, InvalidValue
Required: False
Position: Named
Default value: Automatic
Accept pipeline input: False
Accept wildcard characters: FalsePrompts you for confirmation before running the cmdlet.
Type: System.Management.Automation.SwitchParameter
Parameter Sets: (All)
Aliases: cf
Required: False
Position: Named
Default value: False
Accept pipeline input: False
Accept wildcard characters: FalseShows what would happen if the cmdlet runs. The cmdlet is not run.
Type: System.Management.Automation.SwitchParameter
Parameter Sets: (All)
Aliases: wi
Required: False
Position: Named
Default value: False
Accept pipeline input: False
Accept wildcard characters: FalseThis cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see about_CommonParameters.
You can't pipe objects to this cmdlet.
This cmdlet returns an object representing the new service.
This cmdlet is only available on Windows platforms.
To run this cmdlet, start PowerShell by using the Run as administrator option.
Beginning in PowerShell 6.0, the command no longer includes the ComputerName parameter. To use
this command on a remote computer, use the Invoke-Command to target a remote system.