
# Get the ten latest application log events $logFile = "$logDir\AppLog_$(Get-Date -format 'yyyy-mm-dd_hh-mm-ss-tt').xml" Copy the code below, paste it into your script editor and save with the file name Get-LatestAppLog.ps1 in any folder you want. Then, export the events to a new XML file in the c:\temp folder. The example script below, when executed, gets the top ten latest events from the application event log. However, using the script below creates an easily verifiable result that can confirm whether the scheduled task worked.

Note that the script below is only a random example and you are not required to use it. Make sure to have your script editor ready. In this example, you will create a task that will call the PowerShell.exe and run a script. When you want a scheduled task to do something, create new task action. As an example, you can customize a task to get removed after a consecutive number of days that the task is unused.ĭuring a scheduled task creation, the principal and settings are not explicitly required.


Adding a security context and a set of related settings is optional. It would help if you had a script editor such as Visual Studio Code, Notepad++, or Windows PowerShell ISE.Ī scheduled task requires a minimum of two components to work action and trigger.Windows PowerShell 5.1 or PowerShell 7.But Windows Server 2012 and newer can do the same. The examples in this article use Windows 10.Below are the requirements to create PowerShell scheduled tasks using PowerShell. Since this is a learning-by-doing type of article, there are some prerequisites so you can follow along. Deleting and Restoring a Scheduled Task.Changing the User Account, Security Options, and Compatibility Settings.
