如何在 PowerShell 中停止具有其依賴服務的服務?
要停止在 PowerShell 中具有依賴服務的服務,請使用 -Force 引數。首先,我們將檢查特定服務有哪些依賴服務,獲取它們使用 -DependentService 引數。
示例
例如,WMI 服務(名稱:Winmgmt)有多個依賴服務。
Get-Service -Name Winmgmt -DependentServices
輸出
tatus Name DisplayName ------ ---- ----------- Running UALSVC User Access Logging Service Stopped smstsmgr ConfigMgr Task Sequence Agent Stopped SepLpsService Symantec Endpoint Protection Local ... Stopped NcaSvc Network Connectivity Assistant Running iphlpsvc IP Helper Running CcmExec SMS Agent Host
現在,我們將使用 -Force 引數停止 Winmgmt 服務及其依賴服務。為了檢查命令程序,添加了 -verbose 引數。
Stop-Service -Name Winmgmt -Force -Verbose
帶有 Displayname,
Stop-Service -DisplayName "Windows Management Instrument" -Force -Verbose
停止依賴服務的另一種方法是首先獲取依賴服務,然後再管道 Stop-Service 引數,並且這次不需要使用 -Force 引數,但這隻會停止依賴服務,而不是指定的服務。
Get-Service Winmgmt -DependentServices | Stop-Service -Verbose
以上命令將停止 Winmgmt 的依賴服務,但不會自我停止。
廣告