[英]Stop the Service, Restart and Start the service using Powershell
我需要停止服務,並且一旦服務停止,我就需要重新啟動系統。 重新啟動后,如果使用Powershell腳本處於停止狀態,我需要啟動該服務。
$stage= get-service -name "chrome"
if ( $stage.Status -eq "Running" )
{
Write-Host "The service " $stage.Name "is running"
Stop-Service -Name 'chrome'
}
if ( $stage.Status -eq "Stopped")
{
Restart-Computer -Wait
Start-Service 'chrome'
}
您可能需要從其他服務器運行代碼以實現您的目標。 如上所述,服務器重新啟動后,您將無法使用相同的腳本恢復原狀。
除此之外,您還需要對腳本進行一些小的更改。 也就是說,您需要在if條件之間再次調用以下代碼。 這樣您將獲得預期的輸出
$ stage = get-service -name“ chrome”
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.