Advertisement
iron-from-sf

Task-manager-create-task

Jun 17th, 2024
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PowerShell 0.90 KB | Source Code | 0 0
  1. # Define variables
  2. $taskName = "Update Power BI Gateway"
  3. $taskActionPath = "powershell.exe"
  4. $taskActionArguments = "-File C:\Path\To\Update-PowerBIGateway.ps1"
  5. $taskTrigger = New-ScheduledTaskTrigger -Monthly -DaysOfMonth 1 -At 2:00AM
  6. $taskPrincipal = New-ScheduledTaskPrincipal -UserId "SYSTEM" -LogonType ServiceAccount -RunLevel Highest
  7. $taskSettings = New-ScheduledTaskSettingsSet -AllowStartIfOnBatteries -DontStopIfGoingOnBatteries -StartWhenAvailable
  8.  
  9. # Define the action for the scheduled task
  10. $taskAction = New-ScheduledTaskAction -Execute $taskActionPath -Argument $taskActionArguments
  11.  
  12. # Create the scheduled task
  13. $task = New-ScheduledTask -Action $taskAction -Principal $taskPrincipal -Trigger $taskTrigger -Settings $taskSettings
  14.  
  15. # Register the scheduled task
  16. Register-ScheduledTask -TaskName $taskName -InputObject $task -Force
  17.  
  18. Write-Host "Scheduled task '$taskName' has been created."
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement