Powershell Task scheduler -2

 Here's a PowerShell script to create a task in the Windows Task Scheduler:

$action = New-ScheduledTaskAction -Execute "Powershell.exe" -Argument "-File C:\path\to\script.ps1" $trigger = New-ScheduledTaskTrigger -Once -At "02/02/2023 10:00 AM" $settings = New-ScheduledTaskSettingsSet Register-ScheduledTask -TaskName "TaskName" -Action $action -Trigger $trigger -Settings $settings

Explanation:


New-ScheduledTaskAction creates the action that the task will perform, in this case running a PowerShell script.

New-ScheduledTaskTrigger creates the trigger that determines when the task will run, in this case it's set to run once on the specified date and time.

New-ScheduledTaskSettingsSet creates the task settings.

Register-ScheduledTask creates the task in the Task Scheduler.

Note that the script assumes that the file "C:\path\to\script.ps1" exists and contains the script that you want to run. You'll need to replace that path with the actual path to your script.

No comments:

Post a Comment