From cfaf139a6ace2362996b43bad40426ef6abbeb80 Mon Sep 17 00:00:00 2001 From: CodingWonders <101426328+CodingWonders@users.noreply.github.com> Date: Mon, 1 Dec 2025 21:29:27 +0100 Subject: [PATCH] [Tweaks] Conditionally determine when to use sc and Set-Service (#3761) * [Tweaks] Conditionally determine when to use sc and Set-Service * Clean up comments in Set-WinUtilService.ps1 Removed comments explaining the handling of auto delayed start for PWSH 5. --------- Co-authored-by: Chris Titus --- functions/private/Set-WinUtilService.ps1 | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/functions/private/Set-WinUtilService.ps1 b/functions/private/Set-WinUtilService.ps1 index d2a7d459..2070c4c0 100644 --- a/functions/private/Set-WinUtilService.ps1 +++ b/functions/private/Set-WinUtilService.ps1 @@ -24,8 +24,12 @@ Function Set-WinUtilService { # Check if the service exists $service = Get-Service -Name $Name -ErrorAction Stop - # Service exists, proceed with changing properties - $service | Set-Service -StartupType $StartupType -ErrorAction Stop + # Service exists, proceed with changing properties -- while handling auto delayed start for PWSH 5 + if (($PSVersionTable.PSVersion.Major -lt 7) -and ($StartupType -eq "AutomaticDelayedStart")) { + sc.exe config $Name start=delayed-auto + } else { + $service | Set-Service -StartupType $StartupType -ErrorAction Stop + } } catch [System.ServiceProcess.ServiceNotFoundException] { Write-Warning "Service $Name was not found" } catch {