Files
winutil/functions/private/Set-WinUtilService.ps1
T

37 lines
951 B
PowerShell
Raw Normal View History

+3
2023-03-07 12:28:00 -08:00
Function Set-WinUtilService {
<#
2023-10-19 17:12:55 -05:00
.SYNOPSIS
Changes the startup type of the given service
+3
2023-03-07 12:28:00 -08:00
2023-10-19 17:12:55 -05:00
.PARAMETER Name
The name of the service to modify
.PARAMETER StartupType
The startup type to set the service to
.EXAMPLE
+3
2023-03-07 12:28:00 -08:00
Set-WinUtilService -Name "HomeGroupListener" -StartupType "Manual"
2023-10-19 17:12:55 -05:00
#>
+3
2023-03-07 12:28:00 -08:00
param (
$Name,
$StartupType
)
2023-07-15 10:42:11 -05:00
try {
Write-Host "Setting Service $Name to $StartupType"
2023-10-19 17:12:55 -05:00
2023-07-15 10:42:11 -05:00
# Check if the service exists
$service = Get-Service -Name $Name -ErrorAction Stop
2023-10-19 17:12:55 -05:00
2023-07-15 10:42:11 -05:00
# Service exists, proceed with changing properties
$service | Set-Service -StartupType $StartupType -ErrorAction Stop
} catch [System.ServiceProcess.ServiceNotFoundException] {
2023-07-15 10:42:11 -05:00
Write-Warning "Service $Name was not found"
} catch {
+3
2023-03-07 12:28:00 -08:00
Write-Warning "Unable to set $Name due to unhandled exception"
2023-07-15 10:42:11 -05:00
Write-Warning $_.Exception.Message
+3
2023-03-07 12:28:00 -08:00
}
2023-10-19 17:12:55 -05:00
+3
2023-03-07 12:28:00 -08:00
}