Hi LucD,
Following you script, I tried to run a script as a scheduled job. This is supported in API, but I am not able to even make it work.
Two issues..
1. I need to apply this to datacenter (which is a managed entity, so should not be a problem), not to a host or vm
2. I get error when I run below script
Exception calling "CreateScheduledTask" with "2" argument(s): "A specified parameter was not correct.
"
At C:\HK-WorkArea\VmWare\PS-Scripts-v1.0.1\stm.ps1:27 char:27
+ $stMgr.CreateScheduledTask( <<<< $dc.MoRef , $tSpec)
-
#Find object on which to perform action (wish to apply task to "DataCenters" object)
$dc = Get-Datacenter | Get-View
#RunScript Action
$rsa = New-Object VMware.Vim.RunScriptAction
$rsa.Script = "C:\WINDOWS\system32\WindowsPowerShell\v1.0\powershell.exe -command 'd:\test.ps1'"
#Scheduler
$dTScheduler = New-Object VMware.Vim.DailyTaskScheduler
$dTScheduler.Hour = 18
$dTScheduler.Minute = 08
$dTScheduler.Interval = 1
#Scheduled Task Spec
$tSpec = New-Object VMware.Vim.ScheduledTaskSpec
$tSpec.Action = $rsa
$tSpec.Description = "My Script Scheduling"
$tSpec.Enabled = $TRUE
$tSpec.Name = "Test Sched."
$tSpec.Notification =
$tSpec.Scheduler = $dTScheduler
#Create Scheduled Task
$serviceInstance = get-view ServiceInstance
$stMgr = Get-View ($serviceInstance.Content.ScheduledTaskManager)
$stMgr.CreateScheduledTask( $dc.MoRef , $tSpec)