I have the following script that successfully creates the scheduled task for a VM. I can see it in the GUI console. It fails to run and has the following error (see below, I do give it enough time before task launches). I even added a reconfigerscheduledtask to "update" but still fails to run. However, if I "edit and save" the same task in the console with no changes, it works as expected. Hope someone can help. Thanks in advanced!
$mytime = " 12:40:00 PM"
$mydate = (Get-Date).ToString("MM/dd/yyyy")+$mytime
Import-Csv -Path $inputfile -header vmname -UseCulture |
ForEach-Object -Process {
$vm = Get-VM -Name $_.vmname
write-host $vm
$spec = New-Object VMware.Vim.ScheduledTaskSpec
$spec.Name = "snap-create-$vm"
$spec.Description = 'Scheduled Snapshot Create'
$spec.Enabled = $true
$spec.Scheduler = New-Object VMware.Vim.WeeklyTaskScheduler
$spec.Scheduler.activeTime = [Datetime] $mydate
$spec.Scheduler.interval = 1
#sun/mon=$false is weekday snapshot schedule
$spec.Scheduler.sunday = $false
$spec.Scheduler.monday = $false
$spec.Scheduler.tuesday = $true
$spec.Scheduler.wednesday = $true
$spec.Scheduler.thursday = $true
$spec.Scheduler.friday = $true
$spec.Scheduler.saturday = $true
$spec.Action = New-Object VMware.Vim.MethodAction
$spec.Action.Name = "CreateSnapshot_Task"
@($snapName,$snapDescription,$snapMemory,$snapQuiesce) |
%{ $arg = New-Object VMware.Vim.MethodActionArgument
$arg.Value = $_
$spec.Action.Argument += $arg }
$scheduledTaskManager.CreateScheduledTask($vm.ExtensionData.MoRef, $spec)
$scheduledTaskManager.ReconfigureScheduledTask($spec)