{"id":16567476,"url":"https://github.com/jdhitsolutions/pstimers","last_synced_at":"2025-10-31T10:15:26.483Z","repository":{"id":61446485,"uuid":"141302811","full_name":"jdhitsolutions/PSTimers","owner":"jdhitsolutions","description":"A PowerShell module with a variety of timer and countdown functions.","archived":false,"fork":false,"pushed_at":"2024-09-05T19:26:36.000Z","size":571,"stargazers_count":20,"open_issues_count":0,"forks_count":2,"subscribers_count":4,"default_branch":"master","last_synced_at":"2025-02-06T09:46:50.981Z","etag":null,"topics":["powershell","powershell-module"],"latest_commit_sha":null,"homepage":"","language":"PowerShell","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/jdhitsolutions.png","metadata":{"files":{"readme":"README.md","changelog":"Changelog.md","contributing":null,"funding":null,"license":"LICENSE.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2018-07-17T14:40:34.000Z","updated_at":"2024-10-03T19:01:08.000Z","dependencies_parsed_at":"2024-05-27T22:00:10.748Z","dependency_job_id":"9237ceaa-28f2-423f-ab66-8713353729eb","html_url":"https://github.com/jdhitsolutions/PSTimers","commit_stats":null,"previous_names":[],"tags_count":14,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jdhitsolutions%2FPSTimers","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jdhitsolutions%2FPSTimers/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jdhitsolutions%2FPSTimers/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jdhitsolutions%2FPSTimers/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/jdhitsolutions","download_url":"https://codeload.github.com/jdhitsolutions/PSTimers/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":238743988,"owners_count":19523217,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["powershell","powershell-module"],"created_at":"2024-10-11T21:06:41.974Z","updated_at":"2025-10-29T00:30:58.426Z","avatar_url":"https://github.com/jdhitsolutions.png","language":"PowerShell","funding_links":[],"categories":[],"sub_categories":[],"readme":"# PSTimers\n\n[![PSGallery Version](https://img.shields.io/powershellgallery/v/PSTimers.png?style=for-the-badge\u0026label=PowerShell%20Gallery)](https://www.powershellgallery.com/packages/PSTimers/) [![PSGallery Downloads](https://img.shields.io/powershellgallery/dt/PSTimers.png?style=for-the-badge\u0026label=Downloads)](https://www.powershellgallery.com/packages/PSTimers/)\n\nA set of PowerShell functions to be used as timers and countdown tools.\n\nThis module is available from the PowerShell Gallery and should install in Windows PowerShell 5.1 and PowerShell 7.\n\n```powershell\nInstall-Module PSTimers\n```\n\nThe commands should also work on PowerShell 7 cross-platform except for those that utilize WPF. It is recommended that you run PowerShell 7.2 or later on non-Windows systems.\n\n## :book: History Runtime\n\nPowerShell 7 will display how long a command took to complete when using `Get-History`. [Get-HistoryRuntime](docs/Get-HistoryRuntime.md) will provide the same functionality in Windows PowerShell. By default, it gets the runtime of the last history item.\n\n```powershell\nPS C:\\\u003e $s = dir c:\\scripts\nPS C:\\\u003e Get-HistoryRuntime\n\n ID RunTime\n -- -------\n292 00:00:00.2392380\n```\n\nThe command has an alias of `ghr` and you can specify any history item.\n\n```powershell\nPS C:\\\u003e ghr 295 -Detail\n\n ID RunTime             Status Command\n -- -------             ------ -------\n295 00:00:07.7998983 Completed get-winevent system -MaxEvents 1000\n```\n\n## :watch: MyTimer\n\n:skull: _The MyTimer class and related commands have been heavily revised and extended. There are several breaking changes from previous versions of this module. It is recommended that you clear existing timers before upgrading and using this version of the module._\n\nThis module incorporates commands from a previous module that creates simple timer objects.\n\n- [Start-MyTimer](docs/Start-MyTimer.md)\n- [Get-MyTimer](docs/Get-MyTimer.md)\n- [Stop-MyTimer](docs/Stop-MyTimer.md)\n- [Suspend-MyTimer](docs/Suspend-MyTimer.md)\n- [Resume-MyTimer](docs/Resume-MyTimer.md)\n- [Reset-MyTimer](docs/Reset-MyTimer.md)\n- [Set-MyTimer](docs/Set-MyTimer.md)\n- [Restart-MyTimer](docs/Restart-MyTimer.md)\n- [Remove-MyTimer](docs/Remove-MyTimer.md)\n- [Import-MyTimer](docs/Import-MyTimer.md)\n- [Export-MyTimer](docs/Export-MyTimer.md)\n\nThe `MyTimer` object is defined in a private PowerShell class.\n\n```powershell\n   TypeName: MyTimer\n\nName            MemberType  Definition\n----            ----------  ----------\nEquals          Method      bool Equals(System.Object obj)\nGetCurrentTimer Method      MyTimer GetCurrentTimer()\nGetHashCode     Method      int GetHashCode()\nGetStatus       Method      timespan GetStatus()\nGetType         Method      type GetType()\nPauseTimer      Method      void PauseTimer()\nRefresh         Method      void Refresh()\nResetTimer      Method      void ResetTimer()\nRestartTimer    Method      void RestartTimer()\nResumeTimer     Method      void ResumeTimer()\nStartTimer      Method      void StartTimer()\nStopTimer       Method      void StopTimer()\nToString        Method      string ToString()\nDescription     Property    string Description {get;set;}\nDuration        Property    timespan Duration {get;set;}\nEnd             Property    datetime End {get;set;}\nName            Property    string Name {get;set;}\nRunning         Property    bool Running {get;set;}\nStart           Property    datetime Start {get;set;}\nStatus          Property    MyTimerStatus Status {get;set;}\nHistory         PropertySet History {Name, Start, End, Duration, Description}\n```\n\nMany of the methods are called from related commands.\n\nYou can create a new timer from the prompt.\n\n```powershell\nPS C:\\\u003e Start-MyTimer revisions -Description \"module updates\"\n\nName               Start                Stop Duration     Status Description\n----               -----                ---- --------     ------ -----------\nrevisions 3/5/2023 11:32:46 AM      00:00:00:00 Running module updates\n```\n\nYou can start as many timers as you need.\n\n```powershell\nPS C:\\\u003e $a = Start-MyTimer mail -Description email\nPS C:\\\u003e $b = Start-MyTimer\n```\n\nUse `Get-MyTimer` to view.\n\n```powershell\nPS C:\\\u003e Get-MyTimer\n\nName               Start                Stop Duration     Status Description\n----               -----                ---- --------     ------ -----------\nrevisions 3/5/2023 11:33:18 AM      00:00:00:42 Running module updates\nmail      3/5/2023 11:33:42 AM      00:00:00:19 Running email\nMyTimer   3/5/2023 11:33:54 AM      00:00:00:06 Running\n```\n\nWhen you are finished, you can stop the timer.\n\n```powershell\nPS C:\\\u003e Stop-MyTimer mail -PassThru\n\nName          Start                Stop                 Duration     Status Desc\n                                                                            ript\n                                                                            ion\n----          -----                ----                 --------     ------ ----\nmail 3/5/2023 11:33:42 AM 3/5/2023 11:39:44 AM 00:00:06:02 Stopped email\n```\n\nThe timer will exist for the duration of your PowerShell session.\n\n```powershell\nPS C:\\\u003e Get-MyTimer -Status Stopped | Select History\n\n\nName        : revisions\nStart       : 3/5/2023 11:33:18 AM\nEnd         : 3/5/2023 11:39:18 AM\nDuration    : 00:05:59.7291106\nDescription : module updates\n\nName        : mail\nStart       : 3/5/2023 11:33:42 AM\nEnd         : 3/5/2023 11:39:44 AM\nDuration    : 00:06:02.1412877\nDescription : email\n```\n\nAlthough there are provisions for exporting and importing timers.\n\nThe module includes a format ps1xml file that uses ANSI to highlight timers based on status.\n\n![Get-MyTimers](images/mytimer.png)\n\nTimers are managed through two hashtables created as global variables, `$MyTimerCollection` and `$MyWatchCollection`. Do not delete these variables. The MyTimer commands will update these hashtables as needed.\n\n## :rocket: Start-PSCountdown\n\nThe [Start-PSCountdown](docs/Start-PSCountdown.md) command uses `Write-Progress` to display countdown information. PowerShell 7.2 uses a minimized progress display and a different set of color options based on `$PSStyle`.\n\n![PS7 PSCountdown](images/ps7-pscountdown.png)\n\nIf you would like to use the legacy progress display in PowerShell 7, you should configure it before running `Start-PSCountdown`.\n\n```powershell\n$PSStyle.View = \"Classic\"\n```\n\nSet it to `Minimal` to restore.\n\n`Start-PSCountdown` will automatically detect `$PSStyle` and adjust colors accordingly. It is recommended that you use PowerShell 7.2 or later.\n\nUse `Ctrl+C` to terminate a countdown.\n\n## :computer: Start-PSTimer\n\nFor a more traditional countdown timer, you can use [Start-PSTimer](docs/Start-PSTimer.md). This is an ideal command when you have a simple countdown, say, from 10. You can invoke a script block at the countdown completion.\n\n```powershell\nPS C:\\\u003e Start-PSTimer  -ScriptBlock {Get-Date} -Message \"Let's Do This Thing!\" -Title \"Get-Ready\"\n```\n\n## WPF-Based Timers\n\nIf you are running a Windows-platform, you can use a WPF-based countdown timer.\n\n### :alarm_clock: PSCountdownTimer\n\nAn alternative to `Start-PSCountdown` is [Start-PSCountdownTimer](docs/Start-PSCountdownTimer.md) and related [Stop-PSCountdownTimer](docs/Stop-PSCountdownTimer.md)\n\n```powershell\n$splat = @{\n    Seconds = 600\n    Message = \"The PowerShell magic begins in \"\n    FontSize= 64\n    Color =\"SpringGreen\"\n    OnTop = $True\n}\nStart-PSCountdownTimer @splat\n```\n\n![PSCountdownTimer](images/pscountdowntimer.png)\n\nThis is a transparent WPF form that displays a countdown timer and an optional message. You can control it by changing values in the `$PSCountdownClock` synchronized hashtable.\n\n```powershell\nPS C:\\\u003e $PSCountdownClock\n\nName                           Value\n----                           -----\nStartingPosition\nRunning                        True\nSeconds                        600\nColor                          SpringGreen\nFontWeight                     Normal\nFontFamily                     Segoi UI\nCurrentPosition                {1334, 532}\nOnTop                          True\nRunspace                       System.Management.Automation.Runspaces.LocalRunspace\nMessage                        The PowerShell magic begins in\nFontStyle                      Normal\nStarted                        10/14/2022 4:21:13 PM\nFontSize                       64\nAlertColor                     Yellow\nWarningColor                   Red\nAlert                          50\nWarning                        30\n\nPS C:\\\u003e $PSCountdownClock.OnTop = $False\n```\n\nAt 50 seconds the color will change to yellow and then to red at 30 seconds.\n\nYou can stop the clock by right-clicking on the form, setting the `Running` hashtable value to `$False`, or running `Stop-PSCountdownTimer`. This is the recommended way. The WPF countdown runs in a separate runspace. If you close the PowerShell session where you started the countdown, the timer will terminate.\n\nBecause the timer runs in a separate runspace, the timer itself cannot initiate an action at the end of the timer. If you would like to create automation around the countdown timer, you could create a PowerShell script like this. The sample requires a Windows platform.\n\n```powershell\nClear-Host\n$splat = @{\n    Seconds = 600\n    Message = \"The PowerShell magic begins in \"\n    FontSize= 64\n    Color =\"SpringGreen\"\n    OnTop = $True\n}\nStart-PSCountdownTimer @splat\nDo {\n    Start-Sleep -Seconds 1\n} While ($PSCountdownClock.Running)\nWrite-Host \"Are you ready for some PowerShell?\" -ForegroundColor magenta -BackgroundColor gray\n\n#play a startup song\nAdd-Type -AssemblyName PresentationCore\n$filename = \"c:\\work\\01-Start.mp3\"\n\n$global:MediaPlayer = New-Object System.Windows.Media.MediaPlayer\n$global:MediaPlayer.Open($filename)\n$global:MediaPlayer.Play()\n\n#the media player launches with no UI. Use the object's methods to control it.\n# MediaPlayer.stop()\n# $MediaPlayer.close()\n```\n\n## :hammer: Related Tools\n\nFor a related project, take a look at the [PSClock](https://github.com/jdhitsolutions/PSClock) module. Or if you need a simple to-do manager, look at the [PSWorkItem](https://github.com/jdhitsolutions/PSWorkItem) module.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjdhitsolutions%2Fpstimers","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjdhitsolutions%2Fpstimers","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjdhitsolutions%2Fpstimers/lists"}