Reworked remove_task for Windows 7 compatibility

This commit is contained in:
Yorick Barbanneau 2016-01-27 15:06:38 +01:00
parent 663e8d3ad2
commit bea2b01cfb

View file

@ -11,28 +11,45 @@ $kbIDs=("KB3075249", #telemetry for Win7/8.1
"KB2876229", "KB2876229",
"KB2953664" "KB2953664"
) )
$sheduledTasks=( $sheduledTasks=(
"launchtrayprocess", @{name = "launchtrayprocess"; directory = "\Microsoft\Windows\Setup\GWX"},
"refreshgwxconfig", @{name = "refreshgwxconfig"; directory = "\Microsoft\Windows\Setup\GWX"},
"refreshgwxconfigandcontent", @{name = "refreshgwxconfigandcontent"; directory = "\Microsoft\Windows\Setup\GWX"},
"regreshgwxcontent" @{name = "regreshgwxcontent"; directory = "\Microsoft\Windows\Setup\GWX"}
) )
function remove_tasks () { function remove_tasks () {
param($taskList) param($taskList)
Foreach ($task in $taskList){ Foreach ($task in $taskList){
Write-Host -ForegroundColor white -NoNewline "Remove Task " $task Write-Host -ForegroundColor white -NoNewline "Remove Task " $task.name
if (Get-ScheduledTask -TaskName $task -ErrorAction SilentlyContinue) { if ($PSVersionTable.PSVersion.Major > 2) {
if (Get-ScheduledTask -TaskName $task.name -ErrorAction SilentlyContinue) {
Write-Host -NoNewline -ForegroundColor DarkGreen " found! " Write-Host -NoNewline -ForegroundColor DarkGreen " found! "
Write-Host -Nonewline -ForegroundColor white "removing ... " Write-Host -Nonewline -ForegroundColor white "removing ... "
Try {Unregister-ScheduledTask -TaskName $task -ErrorAction SilentlyContinue -Confirm:$false} Try {Unregister-ScheduledTask -TaskName $task.name -ErrorAction SilentlyContinue -Confirm:$false}
Catch { Catch {
Write-Host -Nonewline -ForegroundColor white " Error " Write-Host -Nonewline -ForegroundColor white " Error "
} }
Write-Host -ForegroundColor Green "Done" Write-Host -ForegroundColor Green " Done"
}
else { Write-Host -ForegroundColor Yellow " Already removed"}
}
else {
$currentTask = $task.directory + "\" + $task.name
if(schtasks /Query /TN $currentTask 2>$null) {
Write-Host -NoNewline -ForegroundColor DarkGreen " found! "
Write-Host -Nonewline -ForegroundColor white "removing ... "
try{
echo $yes | schtasks /Delete /TN $currentTask /F 2>$null
}
Catch {
Write-Host -Nonewline -ForegroundColor white " Error "
}
Write-Host -ForegroundColor green "Done"
}
else { Write-Host -ForegroundColor Yellow " Already removed"}
} }
else { Write-Host -ForegroundColor Yellow "Already removed"}
} }
} }