Created
June 16, 2022 03:43
-
-
Save aymenjaz/b7a6c289b7c9edf3476ef335d6f9f197 to your computer and use it in GitHub Desktop.
Create Task Schedule in windows operating System using Powershell
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$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