mirror of
https://github.com/ChrisTitusTech/winutil.git
synced 2024-11-14 06:35:51 -06:00
d5047e9a8d
* Fixes for netsh and update reset * Allow remotesigned * Fix unattended sleep timer to show * Fix Service Tweaks * Fix Multiple HTTPS connect issues
43 lines
1.2 KiB
PowerShell
43 lines
1.2 KiB
PowerShell
Function Set-WinUtilService {
|
|
<#
|
|
|
|
.DESCRIPTION
|
|
This function will change the startup type of services and start/stop them as needed
|
|
|
|
.EXAMPLE
|
|
|
|
Set-WinUtilService -Name "HomeGroupListener" -StartupType "Manual"
|
|
|
|
#>
|
|
param (
|
|
$Name,
|
|
$StartupType
|
|
)
|
|
try {
|
|
Write-Host "Setting Service $Name to $StartupType"
|
|
|
|
# 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
|
|
|
|
if ($StartupType -eq "Disabled") {
|
|
Write-Host "Stopping $Name"
|
|
Stop-Service -Name $Name -Force -ErrorAction Stop
|
|
}
|
|
elseif ($StartupType -eq "Manual") {
|
|
Write-Host "Stopping $Name"
|
|
Stop-Service -Name $Name -Force -ErrorAction Stop
|
|
}
|
|
}
|
|
catch [System.ServiceProcess.ServiceNotFoundException] {
|
|
Write-Warning "Service $Name was not found"
|
|
}
|
|
catch {
|
|
Write-Warning "Unable to set $Name due to unhandled exception"
|
|
Write-Warning $_.Exception.Message
|
|
}
|
|
|
|
}
|