다음을 통해 공유


New-Service

Creates a new Windows service.

구문

Default (기본값)

New-Service
    [-Name] <String>
    [-BinaryPathName] <String>
    [-DisplayName <String>]
    [-Description <String>]
    [-SecurityDescriptorSddl <String>]
    [-StartupType <ServiceStartupType>]
    [-Credential <PSCredential>]
    [-DependsOn <String[]>]
    [-WhatIf]
    [-Confirm]
    [<CommonParameters>]

Description

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.

예제

Example 1: Create a service

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

This command creates a service named TestService.

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

$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 @params

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.

Example 3: View 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.

Example 4: Set the SecurityDescriptor of a service when creating.

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 @params

The SecurityDescriptor is stored in the $SDDLToSet variable. The SecurityDescriptorSddl parameter uses $SDDL to set the SecurityDescriptor of the new service.

매개 변수

-BinaryPathName

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.

매개 변수 속성

형식:String
Default value:None
와일드카드 지원:False
DontShow:False
별칭:Path

매개 변수 집합

(All)
Position:1
필수:True
파이프라인의 값:False
속성 이름별 파이프라인의 값:False
나머지 인수의 값:False

-Confirm

Prompts you for confirmation before running the cmdlet.

매개 변수 속성

형식:SwitchParameter
Default value:False
와일드카드 지원:False
DontShow:False
별칭:cf

매개 변수 집합

(All)
Position:Named
필수:False
파이프라인의 값:False
속성 이름별 파이프라인의 값:False
나머지 인수의 값:False

-Credential

Specifies 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?.

매개 변수 속성

형식:PSCredential
Default value:None
와일드카드 지원:False
DontShow:False

매개 변수 집합

(All)
Position:Named
필수:False
파이프라인의 값:False
속성 이름별 파이프라인의 값:False
나머지 인수의 값:False

-DependsOn

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

매개 변수 속성

형식:

String[]

Default value:None
와일드카드 지원:False
DontShow:False

매개 변수 집합

(All)
Position:Named
필수:False
파이프라인의 값:False
속성 이름별 파이프라인의 값:False
나머지 인수의 값:False

-Description

Specifies a description of the service.

매개 변수 속성

형식:String
Default value:None
와일드카드 지원:False
DontShow:False

매개 변수 집합

(All)
Position:Named
필수:False
파이프라인의 값:False
속성 이름별 파이프라인의 값:False
나머지 인수의 값:False

-DisplayName

Specifies a display name for the service.

매개 변수 속성

형식:String
Default value:None
와일드카드 지원:False
DontShow:False

매개 변수 집합

(All)
Position:Named
필수:False
파이프라인의 값:False
속성 이름별 파이프라인의 값:False
나머지 인수의 값:False

-Name

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

매개 변수 속성

형식:String
Default value:None
와일드카드 지원:False
DontShow:False
별칭:ServiceName

매개 변수 집합

(All)
Position:0
필수:True
파이프라인의 값:False
속성 이름별 파이프라인의 값:False
나머지 인수의 값:False

-SecurityDescriptorSddl

Specifies the SecurityDescriptor for the service in Sddl format.

매개 변수 속성

형식:String
Default value:None
와일드카드 지원:False
DontShow:False
별칭:sd

매개 변수 집합

(All)
Position:Named
필수:False
파이프라인의 값:False
속성 이름별 파이프라인의 값:False
나머지 인수의 값:False

-StartupType

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

매개 변수 속성

형식:ServiceStartupType
Default value:Automatic
허용되는 값:Automatic, Manual, Disabled, AutomaticDelayedStart, InvalidValue
와일드카드 지원:False
DontShow:False

매개 변수 집합

(All)
Position:Named
필수:False
파이프라인의 값:False
속성 이름별 파이프라인의 값:False
나머지 인수의 값:False

-WhatIf

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

매개 변수 속성

형식:SwitchParameter
Default value:False
와일드카드 지원:False
DontShow:False
별칭:wi

매개 변수 집합

(All)
Position:Named
필수:False
파이프라인의 값:False
속성 이름별 파이프라인의 값:False
나머지 인수의 값:False

CommonParameters

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

입력

None

You can't pipe objects to this cmdlet.

출력

ServiceController

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.