Run Tasks on Timers in PowerShell

Описание к видео 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:   / trevorsullivan  
Twitter:   / pcgeek86  
LinkedIn:   / trevor-sullivan  

#Microsoft #PowerShell #Developer

Комментарии

Информация по комментариям в разработке