- 1 year ago
Add monthly clustered task in PowerShell
Comment
1 / 1
To add a monthly clustered task in PowerShell, you can use the Register-ScheduledTask
cmdlet with the appropriate parameters. Here's an example that demonstrates how to create a monthly clustered task:
powershell# Import the ScheduledTasks module
Import-Module ScheduledTasks
# Define the task action
$action = New-ScheduledTaskAction -Execute "C:\Path\to\your\script.ps1"
# Define the task trigger for the monthly schedule
$trigger = New-ScheduledTaskTrigger -Once -At (Get-Date).AddMonths(1) -MonthsInterval 1
# Define the task settings
$settings = New-ScheduledTaskSettingsSet -AllowStartIfOnBatteries
# Register the scheduled task
Register-ScheduledTask -TaskName "MonthlyClusteredTask" -Action $action -Trigger $trigger -Settings $settings -User "DOMAIN\Username" -Password "YourPassword"
In the above example:
- Replace
"C:\Path\to\your\script.ps1"
with the path to your actual script that you want to run monthly. - Adjust the
-At (Get-Date).AddMonths(1)
to specify the exact date and time when the task should be triggered. By default, it uses the current date and adds one month to it. - Replace
"DOMAIN\Username"
with the domain and username under which the task should run. Also, replace"YourPassword"
with the corresponding user's password.
Running this PowerShell script will create a monthly clustered task that executes the specified script at the specified time. Adjust the parameters as needed to fit your specific requirements.