[CmdletBinding()] param( [Parameter(Mandatory = $true)] [string]$At, [string]$Message = 'Пора вставать', [switch]$NextDay, [switch]$NoBeep ) $ErrorActionPreference = 'Stop' $target = [datetime]::MinValue if (-not [datetime]::TryParse($At, [ref]$target)) { throw "Не удалось разобрать время: $At" } $now = Get-Date if ($target -le $now) { if ($NextDay) { $target = $target.AddDays(1) } else { throw 'Время уже прошло. Добавьте -NextDay или укажите другую дату.' } } $total = [math]::Max(1, ($target - $now).TotalSeconds) Write-Host ("Будильник на {0}" -f $target.ToString('yyyy-MM-dd HH:mm:ss')) while ((Get-Date) -lt $target) { $left = $target - (Get-Date) $done = 100 - [math]::Round(($left.TotalSeconds / $total) * 100, 0) Write-Progress -Activity 'Будильник' -Status ("Осталось {0:hh\:mm\:ss}" -f $left) -PercentComplete $done Start-Sleep -Seconds 1 } Write-Progress -Activity 'Будильник' -Completed if (-not $NoBeep) { for ($i = 0; $i -lt 5; $i++) { [console]::Beep(1000, 500) Start-Sleep -Milliseconds 200 } } $shell = New-Object -ComObject WScript.Shell $shell.Popup($Message, 60, 'Будильник', 64) | Out-Null Write-Host ($Message)