I am trying below script from LucD (Schedule Snapshot with PowerCli ), but always stuck in last line with error mentioned below. Need help,
$vmName='MyVM'
$snapTime=Get-Date"31/10/16 23:00"
$snapName='Test'
$snapDescription='Scheduled snapshot'
$snapMemory=$false
$snapQuiesce=$true
$emailAddr='lucd@lucd.info'
###############
$vm=Get-VM-Name$vmName
$si=get-viewServiceInstance
$scheduledTaskManager=Get-View$si.Content.ScheduledTaskManager
$spec=New-ObjectVMware.Vim.ScheduledTaskSpec
$spec.Name ="Snapshot",$_.VMname -join' '
$spec.Description ="Take a snapshot of $($vm.Name)"
$spec.Enabled =$true
$spec.Notification =$emailAddr
$spec.Scheduler =New-ObjectVMware.Vim.OnceTaskScheduler
$spec.Scheduler.runat =$snapTime
$spec.Action =New-ObjectVMware.Vim.MethodAction
$spec.Action.Name ="CreateSnapshot_Task"
@($snapName,$snapDescription,$snapMemory,$snapQuiesce) |%{
$arg=New-ObjectVMware.Vim.MethodActionArgument
$arg.Value =$_
$spec.Action.Argument +=$arg
}
$scheduledTaskManager.CreateObjectScheduledTask($vm.ExtensionData.MoRef,$spec)
================================================================================================
Error:
Cannot convert argument "spec", with value: "VMware.Vim.ScheduledTaskSpec", for "CreateObjectScheduledTask" to type "VMware.Vim.ScheduledTaskSpec": "Cannot convert the
"VMware.Vim.ScheduledTaskSpec" value of type "VMware.Vim.ScheduledTaskSpec" to type "VMware.Vim.ScheduledTaskSpec"."
At line:66 char:1
+ $scheduledTaskManager.CreateObjectScheduledTask($vm.ExtensionData.MoR ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [], MethodException
+ FullyQualifiedErrorId : MethodArgumentConversionInvalidCastArgument