服務
概要
管理 Windows 服務。
語法
Service [String] #ResourceName
{
Name = [string]
[BuiltInAccount = [string]{ LocalService | LocalSystem | NetworkService }]
[Credential = [PSCredential]]
[Dependencies = [string[]]]
[DependsOn = [string[]]]
[Description = [string]]
[DesktopInteract = [bool]]
[DisplayName = [string]]
[Ensure = [string]{ Absent | Present }]
[Path = [string]]
[PsDscRunAsCredential = [PSCredential]]
[StartupTimeout = [UInt32]]
[StartupType = [string]{ Automatic | Disabled | Manual }]
[State = [string]{ Ignore | Running | Stopped }]
[TerminateTimeout = [UInt32]]
}
描述
資源 Service
可讓您新增、更新和移除服務。
規格需求
無。
金鑰屬性
名稱
將服務名稱指定為字串。
注意
有時候這個值與顯示名稱不同。 您可以使用 Get-Service
Cmdlet 取得服務清單及其目前狀態。
Type: System.String
選擇性屬性
BuiltInAccount
指定要執行服務的電腦帳戶名稱。 帳戶必須能夠存取 Path 所指定的可執行檔,才能啟動服務。
請勿使用 Credential 屬性來指定此屬性。
Type: System.String
Accepted Values:
- LocalService
- LocalSystem
- NetworkService
Default Value: Null
認證
指定要執行服務之帳戶的認證。 帳戶必須能夠存取 Path 所指定的可執行檔,才能啟動服務。 資源會自動授與此帳戶「以服務登入」許可權。
請勿使用 BuiltInAccount 屬性來指定此屬性。
Type: System.Management.Automation.PSCredential
Default Value: None
相依性
指定此服務需要以字串陣列的形式執行的服務名稱。
Type: System.String[]
Default Value: None
描述
將服務的描述指定為字串。 服務描述會出現在 電腦管理、服務中。
Type: System.String
Default Value: None
DesktopInteract
指定服務是否可以在桌面上建立或與視窗通訊。 如果BuiltInAccount未指定為 LocalSystem
,則此屬性必須是 $false
。
預設值是 $false
。
Type: System.Boolean
Default Value: false
DisplayName
將服務的易記顯示名稱指定為字串。
Type: System.String
Default Value: None
Ensure
指定服務是否應該存在。 若要新增或更新服務,請將此屬性設定為 Present
。 若要移除服務,請將此屬性設定為 Absent
。
預設值是 Present
。
Type: System.String
Accepted Values:
- Absent
- Present
Default Value: Present
路徑
將服務可執行檔的路徑指定為字串。 如果服務不存在,則需要這個屬性。
Type: System.String
Default Value: None
StartupTimeout
指定等候服務以毫秒為單位啟動的時間。
預設值是 30000
。
Type: System.UInt32
Default Value: 30000
StartupType
指定服務在系統啟動上的行為。 此值必須是下列其中之一:
Automatic
- 服務是由作業系統在系統啟動時啟動。 如果自動啟動的服務相依于手動啟動的服務,則手動啟動的服務也會在系統啟動時自動啟動。Disabled
- 服務已停用,且無法由使用者或應用程式啟動。Manual
- 服務只會由使用者、使用服務控制管理員或應用程式手動啟動。
如果服務不存在,預設值為 Automatic
。
Type: System.String
Behavior: Write
Accepted Values:
- Automatic
- Disabled
- Manual
Default Value: None
State
指定服務是否應該執行。 此值必須是下列其中之一:
Running
- 如果尚未啟動,資源就會啟動服務。Stopped
- 如果服務正在執行,資源就會停止服務。Ignore
- 資源不會啟動或停止服務。
預設值是 Running
。
Type: System.String
Accepted Values:
- Running
- Stopped
- Ignore
Default Value: Running
TerminateTimeout
指定等候服務停止的時間,以毫秒為單位。 預設值是 30000
。
Type: System.UInt32
Default Value: 30000
範例
意見反應
https://aka.ms/ContentUserFeedback。
即將登場:在 2024 年,我們將逐步淘汰 GitHub 問題作為內容的意見反應機制,並將它取代為新的意見反應系統。 如需詳細資訊,請參閱:提交並檢視相關的意見反應