<# .SYNOPSIS Register (or remove) a Windows Scheduled Task that runs the leak scan on a fixed interval. .DESCRIPTION Creates a task named "DeepSeekLeakScan" that calls run_scan.ps1 as your user, at a fixed local time. The task does not need the machine to be unlocked, but it does need the token file to exist and be readable by you. The scan is read-only against GitHub's public API. It never calls the DeepSeek API and never spends anyone's credits. .PARAMETER Schedule Daily or Weekly. .PARAMETER Time Local time of day, "HH:mm". Default 09:00. .PARAMETER Day Weekday for -Schedule Weekly. Default Monday. .PARAMETER EveryNDays Interval for -Schedule Daily. Default 1. .PARAMETER Unregister Remove the task instead of creating it. .EXAMPLE .\register-task.ps1 -Schedule Weekly -Time 09:00 -Day Monday .\register-task.ps1 -Schedule Daily -EveryNDays 3 -Time 22:30 .\register-task.ps1 -Unregister #> [CmdletBinding()] param( [ValidateSet('Daily', 'Weekly')] [string]$Schedule = 'Weekly', [string]$Time = '09:00', [ValidateSet('Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday', 'Sunday')] [string]$Day = 'Monday', [int]$EveryNDays = 1, [switch]$Unregister ) $ErrorActionPreference = 'Stop' $taskName = 'DeepSeekLeakScan' $runner = Join-Path $PSScriptRoot 'run_scan.ps1' if ($Unregister) { $existing = Get-ScheduledTask -TaskName $taskName -ErrorAction SilentlyContinue if (-not $existing) { Write-Host "No task named '$taskName' is registered." exit 0 } Unregister-ScheduledTask -TaskName $taskName -Confirm:$false Write-Host "Removed scheduled task '$taskName'." exit 0 } if (-not (Test-Path $runner)) { throw "run_scan.ps1 not found next to register-task.ps1" } if ($Time -notmatch '^\d{1,2}:\d{2}$') { throw "Time must look like 09:00 or 22:30, got '$Time'" } $action = New-ScheduledTaskAction ` -Execute 'powershell.exe' ` -Argument "-NoProfile -ExecutionPolicy Bypass -File `"$runner`"" ` -WorkingDirectory $PSScriptRoot $trigger = if ($Schedule -eq 'Weekly') { New-ScheduledTaskTrigger -Weekly -DaysOfWeek $Day -At $Time } else { New-ScheduledTaskTrigger -Daily -DaysInterval $EveryNDays -At $Time } $settings = New-ScheduledTaskSettingsSet ` -StartWhenAvailable ` -MultipleInstances IgnoreNew ` -ExecutionTimeLimit (New-TimeSpan -Hours 2) ` -AllowStartIfOnBatteries ` -DontStopIfGoingOnBatteries Register-ScheduledTask ` -TaskName $taskName ` -Action $action ` -Trigger $trigger ` -Settings $settings ` -Description 'Scan public GitHub repos for leaked DeepSeek keys and build a masked disclosure report. Read-only; no DeepSeek API calls.' ` -Force | Out-Null $when = if ($Schedule -eq 'Weekly') { "every $Day at $Time" } else { "every $EveryNDays day(s) at $Time" } Write-Host "Registered '$taskName' - runs $when." Write-Host "" Write-Host "Test it now without waiting:" Write-Host " Start-ScheduledTask -TaskName $taskName" Write-Host " Get-ScheduledTaskInfo -TaskName $taskName" Write-Host "" Write-Host "Logs land in: $(Join-Path $PSScriptRoot 'out\logs')" Write-Host "Remove it later with: .\register-task.ps1 -Unregister"