Which PowerCLI version are you using?
Check with
Get-Module -Name VMware* -ListAvailable
Where there any other errors before this one?
You did adjust the values at the beginning for your environment I assume?
Can you replace this line
$scheduledTaskManager.CreateObjectScheduledTask($vm.ExtensionData.MoRef, $spec)
with these line, and tell us what it says?
Make sure to hide any sensitive information.
$spec.GetType().Name
$spec | format-custom -Depth 2
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference