Skip to content

Instantly share code, notes, and snippets.

@aymenjaz
Created June 16, 2022 03:43
Show Gist options
  • Save aymenjaz/b7a6c289b7c9edf3476ef335d6f9f197 to your computer and use it in GitHub Desktop.
Save aymenjaz/b7a6c289b7c9edf3476ef335d6f9f197 to your computer and use it in GitHub Desktop.
Create Task Schedule in windows operating System using Powershell
$TaskName = 'MyScript'
$User= "NT AUTHORITY\SYSTEM"
$ScriptPath = "C:\scripts\script.ps1"
$Trigger= New-ScheduledTaskTrigger -At 22:00 -Daily
$Action= New-ScheduledTaskAction -Execute "PowerShell.exe" -Argument "-WindowStyle Hidden -executionpolicy unrestricted -noprofile -file $ScriptPath"
Register-ScheduledTask -TaskName $TaskName -Trigger $Trigger -User $User -Action $Action -RunLevel Highest -Force
<#
# If you want the task to run every time during the computer startup, the first command has to be as follows:
$Trigger= New-ScheduledTaskTrigger -AtStartup
# If you want to run a task when a user logs on:
$Trigger= New-ScheduledTaskTrigger -AtLogon
#>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment