From bd43288f99a5dd388ed6151a172c88d2bf840632 Mon Sep 17 00:00:00 2001 From: Chris Titus Date: Tue, 18 Oct 2022 08:21:44 -0500 Subject: [PATCH] fix stuck service tweaks --- winutil.ps1 | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/winutil.ps1 b/winutil.ps1 index 53b0f47d..43e13ebd 100644 --- a/winutil.ps1 +++ b/winutil.ps1 @@ -569,9 +569,12 @@ Write-Logs -Level INFO -Message "Starting Services Modification" -LogPath $sync.logfile $ServicesToModify | ForEach-Object { - Stop-Service "$($psitem.name)" - Set-Service "$($psitem.name)" -StartupType $($psitem.StartupType) - Write-Logs -Level INFO -Message "Service $($psitem.name) set to $($psitem.StartupType)" -LogPath $sync.logfile + $service = Get-Service -Name W32Time -ErrorAction SilentlyContinue + if ($service.Length -gt 0) { + Stop-Service "$($psitem.name)" + Set-Service "$($psitem.name)" -StartupType $($psitem.StartupType) + Write-Logs -Level INFO -Message "Service $($psitem.name) set to $($psitem.StartupType)" -LogPath $sync.logfile + } } Write-Logs -Level INFO -Message "Finished setting Services" -LogPath $sync.logfile