#Requires -Version 5.1 <# .SYNOPSIS DMF Crawler 작업 3종(Daily / Agent / AgyUpdate)을 제거한다. .DESCRIPTION 데이터·로그·리포트는 건드리지 않는다. install_tasks.ps1 이 만든 4개 작업 이름(프로브 포함)을 모두 대상으로 하며, 없는 것은 조용히 건너뛴다 (멱등). 실행 중인 작업은 먼저 중지한 뒤 제거한다. .PARAMETER TaskPath 작업 스케줄러 폴더. install_tasks.ps1 과 동일한 기본값을 쓴다. .PARAMETER RemoveFolder 작업 3종 제거 후 '\DMF_Crawler\' 폴더 자체도 지운다(비어 있을 때만 의미가 있다 — 다른 작업이 같은 폴더에 남아 있으면 실패해도 무해하다). .EXAMPLE powershell -ExecutionPolicy Bypass -File .\scripts\uninstall_tasks.ps1 .EXAMPLE powershell -ExecutionPolicy Bypass -File .\scripts\uninstall_tasks.ps1 -RemoveFolder #> [CmdletBinding()] param( [string]$TaskPath = '\DMF_Crawler\', [switch]$RemoveFolder ) Set-StrictMode -Version Latest $ErrorActionPreference = 'Stop' function Write-Step { param([string]$Message) Write-Host "[uninstall_tasks] $Message" } function Write-Warn { param([string]$Message) Write-Host "[uninstall_tasks] ! $Message" -ForegroundColor Yellow } function Write-Good { param([string]$Message) Write-Host "[uninstall_tasks] + $Message" -ForegroundColor Green } # install_tasks.ps1 이 만드는 이름 전부(일회성 -Verify 프로브까지 포함해 # 흔적이 남지 않게 한다). $names = @('DMF_Crawler_Daily', 'DMF_Crawler_Agent', 'DMF_Crawler_AgyUpdate', 'DMF_Crawler_Probe') $removed = 0 $missing = 0 $failed = 0 foreach ($n in $names) { $t = Get-ScheduledTask -TaskName $n -TaskPath $TaskPath -ErrorAction SilentlyContinue if (-not $t) { Write-Step "없음(건너뜀): $TaskPath$n" $missing++ continue } try { if ($t.State -eq 'Running') { Write-Step "실행 중 → 중지: $n" Stop-ScheduledTask -TaskName $n -TaskPath $TaskPath -ErrorAction SilentlyContinue } Unregister-ScheduledTask -TaskName $n -TaskPath $TaskPath -Confirm:$false Write-Good "제거: $TaskPath$n" $removed++ } catch { Write-Warn "제거 실패: $TaskPath$n ($($_.Exception.Message))" $failed++ } } if ($RemoveFolder) { $svc = $null try { $svc = New-Object -ComObject 'Schedule.Service' $svc.Connect() $root = $svc.GetFolder('\') $root.DeleteFolder($TaskPath.Trim('\'), 0) Write-Good "폴더 제거: $TaskPath" } catch { Write-Warn "폴더 제거 실패(무해 — 안에 다른 작업이 남아 있을 수 있습니다): $($_.Exception.Message)" } finally { if ($svc) { [void][System.Runtime.InteropServices.Marshal]::ReleaseComObject($svc) } } } Write-Host '' Write-Step "요약: 제거 $removed / 이미 없음 $missing / 실패 $failed" Write-Host '완료. data\ logs\ reports\ backup\ state\ 는 그대로 남아 있습니다.' if ($failed -gt 0) { exit 1 } exit 0