title: Creating Scheduled Task using PowerShell
body: <p>I am working on script which will execute on next day and then will run every other 1,2 and 3 day(s). Here is my script:</p>
  
  <pre><code>#The script below will run as the specified user (you will be prompted for credentials)
  #PATH C:\backup\scripts\ will need to be replaced and created in preferred location where the respective backup scripts will be stored
  
  $jobname0 = "Full Backup"
  $jobname1 = "Incremental Backup1"
  $jobname2 = "Incremental Backup2"
  # Change these script location to whatever you want
  $script0 = "C:\backup\scripts\full.bat"
  $script1 =  "C:\backup\scripts\inc1.cmd"
  $script2 =  "C:\backup\scripts\inc2.ps1"
  $repeat = (New-TimeSpan -Hours 72 )
  
  
  # and is set to be elevated to use the highest privileges.
  # The task will run every 72hrs (3days) specified in $repeat.
  $action0 = New-ScheduledTaskAction –Execute "$pshome\powershell.exe" -Argument  "$script0; quit"
  $action1 = New-ScheduledTaskAction –Execute "$pshome\powershell.exe" -Argument  "$script1; quit"
  $action2 = New-ScheduledTaskAction –Execute "$pshome\powershell.exe" -Argument  "$script2; quit"
  
  $duration = (New-TimeSpan -Days (365 * 20))
  $trigger0 = New-ScheduledTaskTrigger -Once -At 00:00AM -RepetitionInterval $repeat -RepetitionDuration $duration
  $trigger1 = New-ScheduledTaskTrigger -Once -At 00:01AM -RepetitionInterval $repeat -RepetitionDuration $duration
  $trigger2 = New-ScheduledTaskTrigger -Once -At (00:01AM).AddTime(48:00) -RepetitionInterval $repeat -RepetitionDuration $duration
  
  $msg = "Enter the username and password that will run the task"; 
  $credential = $Host.UI.PromptForCredential("Task username and password",$msg,"$env:userdomain\$env:username",$env:userdomain)
  $username = $credential.UserName
  $password = $credential.GetNetworkCredential().Password
  $settings = New-ScheduledTaskSettingsSet -AllowStartIfOnBatteries -DontStopIfGoingOnBatteries -StartWhenAvailable -RunOnlyIfNetworkAvailable -DontStopOnIdleEnd
  
  Register-ScheduledTask -TaskName $jobname0 -Action $action0 -Trigger $trigger0 -RunLevel Highest -User $username -Password $password -Settings $settings 
  Register-ScheduledTask -TaskName $jobname1 -Action $action1 -Trigger $trigger1 -RunLevel Highest -User $username -Password $password -Settings $settings 
  Register-ScheduledTask -TaskName $jobname2 -Action $action2 -Trigger $trigger2 -RunLevel Highest -User $username -Password $password -Settings $settings
  </code></pre>
  
  <p>How I can add days instead of time into the trigger. I appreciate all your help.</p>