[CmdletBinding()] param( [ValidateSet('Add', 'List', 'Due', 'Done')] [string]$Action = 'List', [string]$Text, [string]$At, [int]$Id, [string]$Data = (Join-Path $env:APPDATA 'Productivity\reminders.json'), [switch]$Popup ) $ErrorActionPreference = 'Stop' function Read-Reminders { param([string]$Path) if (-not (Test-Path -LiteralPath $Path)) { return @() } $raw = Get-Content -LiteralPath $Path -Raw -Encoding UTF8 if ([string]::IsNullOrWhiteSpace($raw)) { return @() } $items = $raw | ConvertFrom-Json if ($null -eq $items) { return @() } return @($items) } function Save-Reminders { param([string]$Path, [object[]]$Items) $directory = Split-Path -LiteralPath $Path if ($directory -and -not (Test-Path -LiteralPath $directory)) { New-Item -ItemType Directory -Path $directory -Force | Out-Null } if (Test-Path -LiteralPath $Path) { Copy-Item -LiteralPath $Path -Destination ($Path + '.bak') -Force } $json = ConvertTo-Json -InputObject @($Items) -Depth 5 Set-Content -LiteralPath $Path -Value $json -Encoding UTF8 } $items = Read-Reminders -Path $Data switch ($Action) { 'Add' { if ([string]::IsNullOrWhiteSpace($Text)) { throw 'Укажите текст напоминания через -Text.' } if ([string]::IsNullOrWhiteSpace($At)) { throw 'Укажите время через -At, например "2026-11-10 09:00".' } $when = [datetime]::MinValue if (-not [datetime]::TryParse($At, [ref]$when)) { throw "Не удалось разобрать дату: $At" } $nextId = 1 if ($items.Count -gt 0) { $nextId = ([int]($items | Measure-Object -Property id -Maximum).Maximum) + 1 } $entry = [pscustomobject]@{ id = $nextId text = $Text at = $when.ToString('s') done = $false } $items = @($items) + $entry Save-Reminders -Path $Data -Items $items Write-Host ("Добавлено #{0}: {1} ({2})" -f $nextId, $Text, $when.ToString('yyyy-MM-dd HH:mm')) } 'List' { if ($items.Count -eq 0) { Write-Host 'Напоминаний нет.' break } $items | Sort-Object -Property at | ForEach-Object { $status = if ($_.done) { 'готово' } else { 'активно' } Write-Host ("#{0} [{1}] {2} - {3}" -f $_.id, $status, $_.at, $_.text) } } 'Due' { $now = Get-Date $due = @($items | Where-Object { -not $_.done -and [datetime]::Parse($_.at) -le $now } | Sort-Object -Property at) if ($due.Count -eq 0) { Write-Host 'Просроченных напоминаний нет.' break } foreach ($item in $due) { $message = "$($item.text)`n$($item.at)" Write-Host ("#{0} {1}" -f $item.id, $message) if ($Popup) { $shell = New-Object -ComObject WScript.Shell $shell.Popup($message, 30, 'Напоминание', 64) | Out-Null } } } 'Done' { if ($Id -le 0) { throw 'Укажите номер напоминания через -Id.' } $found = $false foreach ($item in $items) { if ([int]$item.id -eq $Id) { $item.done = $true $found = $true } } if (-not $found) { throw "Напоминание #$Id не найдено." } Save-Reminders -Path $Data -Items $items Write-Host "Напоминание #$Id отмечено выполненным." } }