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

43 lines
1.2 KiB
PowerShell
Raw Normal View History

+3
2023-03-07 12:28:00 -08:00
function Set-WinUtilScheduledTask {
<#
2023-10-19 17:12:55 -05:00
.SYNOPSIS
Enables/Disables the provided Scheduled Task
+3
2023-03-07 12:28:00 -08:00
2023-10-19 17:12:55 -05:00
.PARAMETER Name
The path to the Scheduled Task
.PARAMETER State
The State to set the Task to
.EXAMPLE
+3
2023-03-07 12:28:00 -08:00
Set-WinUtilScheduledTask -Name "Microsoft\Windows\Application Experience\Microsoft Compatibility Appraiser" -State "Disabled"
2023-10-19 17:12:55 -05:00
+3
2023-03-07 12:28:00 -08:00
#>
param (
$Name,
$State
)
try {
if($State -eq "Disabled") {
+3
2023-03-07 12:28:00 -08:00
Write-Host "Disabling Scheduled Task $Name"
Disable-ScheduledTask -TaskName $Name -ErrorAction Stop
}
if($State -eq "Enabled") {
+3
2023-03-07 12:28:00 -08:00
Write-Host "Enabling Scheduled Task $Name"
Enable-ScheduledTask -TaskName $Name -ErrorAction Stop
}
} catch [System.Exception] {
if($psitem.Exception.Message -like "*The system cannot find the file specified*") {
+3
2023-03-07 12:28:00 -08:00
Write-Warning "Scheduled Task $name was not Found"
} else {
+3
2023-03-07 12:28:00 -08:00
Write-Warning "Unable to set $Name due to unhandled exception"
Write-Warning $psitem.Exception.Message
}
} catch {
+3
2023-03-07 12:28:00 -08:00
Write-Warning "Unable to run script for $name due to unhandled exception"
2023-10-19 17:12:55 -05:00
Write-Warning $psitem.Exception.StackTrace
+3
2023-03-07 12:28:00 -08:00
}
}