Last active
December 6, 2020 00:15
-
-
Save pferreirafabricio/f4b7e2147d46b024bf2a9cb8ccaafc65 to your computer and use it in GitHub Desktop.
Create a scheduled task that will run a PowerShell script at 1:00 AM, in this example a script that will make a backup of a MongoDB Database
This file contains 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
$scriptToExecutePath = "C:\Path\To\dump-script.ps1"; | |
$taskName = "MongoDB Backup - <databaseName>" | |
$taskDescription = "Make a dump of <databaseName> database" | |
$action = New-ScheduledTaskAction ` | |
-Execute 'C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe' ` | |
-Argument "-NoProfile -NoLogo -NonInteractive -ExecutionPolicy Bypass -File $scriptToExecutePath" | |
$trigger = New-ScheduledTaskTrigger -Daily -At 1am | |
$taskSettings = New-ScheduledTaskSettingsSet -Compatibility Win8 | |
Register-ScheduledTask ` | |
-TaskName $taskName ` | |
-Action $action ` | |
-Trigger $trigger ` | |
-Settings $taskSettings ` | |
-Description $taskDescription | |
# OBS: If you need to run the task manually for testing use: | |
# Start-ScheduledTask -TaskName 'MongoDB Backup - <databaseName>' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment