I am using VI SDK to create a custom scheduled task in Virtual Center. I intent to run a powershell script that connects to VC and does somethings. This appears possible while looking at API (http://pubs.vmware.com/vi-sdk/visdk250/ReferenceGuide/vim.action.RunScriptAction.html)
API says it can run "shell" scripts..DOS shell or PowerShell ? Will it allow passthrough login to VC as it is running as scheduled task ?
Can the gurus help confirm if this can achieve intented results ?
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)
Can someone help please...
-
#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.Scheduler = $dTScheduler
#Create Scheduled Task
$serviceInstance = get-view ServiceInstance
$stMgr = Get-View ($serviceInstance.Content.ScheduledTaskManager)
$stMgr.CreateScheduledTask( $dc.MoRef , $tSpec)
anyone to help here ..
The RunScriptAction is only available for Alarms I'm afraid.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Thanks for looking into this. Guess we have no where to go with VC2.5u5