Загрузка страницы

Run Tasks on Timers in PowerShell

You can use PowerShell to run tasks on periodic timers. For example, let's say that you want to clean up a folder with old log files on an hourly basis. Instead of using your operating system's task scheduler (ie. systemd on Linux, MacOS, or Windows Task Scheduler), you can use PowerShell to create a Timer.

The .NET Framework has a class named Timer in the System.Timers namespace, defined in System.ComponentModel.TypeConverter.dll. There are two constructors for the Timer class, one with zero parameters, and one that accepts a single "double" value as input. The "double" value is the interval, in milliseconds, that the Timer will operate on.

Once you've created a Timer object, you use the Register-ObjectEvent command to register for the "Elapsed" .NET event. On this same command, the -Action parameter allows you to specify a PowerShell ScriptBlock (aka. anonymous function) that will be executed every time the Timer elapses.

Producer: Trevor Sullivan
Website: https://trevorsullivan.net
Patreon: https://patreon.com/trevorsullivan
Twitter: https://twitter.com/pcgeek86
LinkedIn: https://www.linkedin.com/in/trevor-sullivan/

#Microsoft #PowerShell #Developer

Видео Run Tasks on Timers in PowerShell канала Trevor Sullivan
Показать
Комментарии отсутствуют
Введите заголовок:

Введите адрес ссылки:

Введите адрес видео с YouTube:

Зарегистрируйтесь или войдите с
Информация о видео
13 декабря 2020 г. 4:01:24
00:17:08
Яндекс.Метрика