3
I'm trying to create a scheduled task with powershell, the task is supposed to run the 1st of every month, but I can't figure out how to use New-ScheduledTaskTrigger with a monthly interval.
EG:
$jobName = "Backup_EMR_Data"
$action = New-ScheduledTaskAction -Execute $actionName -Argument $arg -WorkingDirectory $SSISPackagePath
$trigger = New-ScheduledTaskTrigger -Daily -At 12:30AM
$settings = New-ScheduledTaskSettingsSet
$task = New-ScheduledTask -Action $action -Trigger $trigger -Settings $settings
Register-ScheduledTask $jobName -InputObject $task -TaskPath $taskPath -User $userName -Password $password
Does this still work with PSv4, which is what the questioner seems to be using? According to this it can't be done directly, and an XML solution is proposed.
– AFH – 2015-11-04T12:32:07.497@AFH I don't know. Lets wait for the OP to respond. – DavidPostill – 2015-11-04T12:35:15.183
PSv3 I don't have any Scheduled Task cmdlets. Schedule Job cmdlets use triggers, and I found the enum values usable for those triggers:
PS > [enum]::GetValues([Microsoft.PowerShell.ScheduledJob.TriggerFrequency])
results inNone
,Once
,Daily
,Weekly
,AtLogon
,AtStartup
. This does not necessarily meanMonthly
is not available to his version/module, but a similar exercise would answer the question. – Xalorous – 2015-11-05T00:35:45.633