I am so close I can feel it! I've been trying to port an example seen in the programming guide (http://www.vmware.com/support/developer/vc-sdk/visdk25pubs/visdk25programmingguide.pdf) p. 163 "Creating a Scheduled Task". I had to leap a few hurdles and now at the end I'm stumped again. Here's the code and the error:
The lsat four lines are what is giving me trouble. Took me a while to determine what obj types the ScheduledTaskManager wanted... But I am not satisfied that I did $vc & stmMoRef correctly. The error I receive is:
cheduletask test.ps1'
Exception calling "CreateScheduledTask" with "2" argument(s): "Object reference not set to an instance of an object."
At C:\documents and settings\hrottenberg\my documents\windowspowershell\scripts\book\scheduletask test.ps1:21 char:25
+ $stm.CreateScheduledTask <<<< ($vmview.MoRef, $tSpec)
Any pointers would be helpful.
-hal
Hal Rottenberg
Co-Host, PowerScripting Podcast (http://powerscripting.net)
# Find object on which to perform action
$vmview = Get-View (Get-VM SDK-XPSP2).ID
$maa = New-Object VMware.Vim.MethodActionArgument
$maa.Value = $vmview.MoRef
$ma = New-Object VMware.Vim.MethodAction
$ma.Argument = $maa
$ma.Name = "powerOnVM"
$dTScheduler = New-Object VMware.Vim.DailyTaskScheduler
$dTScheduler.Hour = 18
$dTScheduler.Minute = 08
$tSpec = New-Object VMware.Vim.ScheduledTaskSpec
$tSpec.Description = "Start virtual machine according to schedule."
$tSpec.Enabled = $TRUE
$tSpec.Name = "Power On Virtual Machine"
$tSpec.Action = $ma
$tSpec.Scheduler = $dTScheduler
$tSpec.Notification = "hal@halr9000.com"
$vc = New-Object VMware.Vim.VimClient
$stmMoRef = New-Object VMware.Vim.ManagedObjectReference
$stm = New-Object VMware.Vim.ScheduledTaskManager $vc,$stmMoRef
$stm.CreateScheduledTask($vmview.MoRef, $tSpec)
The lsat four lines are what is giving me trouble. Took me a while to determine what obj types the ScheduledTaskManager wanted... But I am not satisfied that I did $vc & stmMoRef correctly. The error I receive is:
cheduletask test.ps1'
Exception calling "CreateScheduledTask" with "2" argument(s): "Object reference not set to an instance of an object."
At C:\documents and settings\hrottenberg\my documents\windowspowershell\scripts\book\scheduletask test.ps1:21 char:25
+ $stm.CreateScheduledTask <<<< ($vmview.MoRef, $tSpec)
Any pointers would be helpful.
-hal
Hal Rottenberg
Co-Host, PowerScripting Podcast (http://powerscripting.net)