I am trying to add some user input to the script as follows: ############### # These are the values you should get from your webform $Vcenter= Read-Host -Prompt "Which Vcenter is the machine...
See more...
I am trying to add some user input to the script as follows: ############### # These are the values you should get from your webform $Vcenter= Read-Host -Prompt "Which Vcenter is the machine located on?" $vmName = Read-Host -Prompt "Snapshot of VM" $date = Read-Host -Prompt "When would you like this to be taken (DD/MM/YY 23:00 Format)" $Owner = Read-Host -Prompt "Who are you?" $requester = Read-Host -Prompt "Email Address of Requester" $SR = Read-Host -Prompt "What is the SR number?" $snapTime = Get-Date "$date" $snapName = "Snapshot of $vmName by $owner on $date per SR $SR" $snapDescription = "Snapshot of $vmName by $owner on $date Per SR $SR" $snapMemory = $false $snapQuiesce = $true $emailAddr = @("Myemailaddress@somewhere.com", "$requester") ############### #Add VMWare Snapin & connect to vcenter Add-PSSnapin VMware.VimAutomation.Core Connect-VIServer -server $Vcenter $vm = Get-VM -Name $vmName $si = get-view ServiceInstance $scheduledTaskManager = Get-View $si.Content.ScheduledTaskManager $spec = New-Object VMware.Vim.ScheduledTaskSpec $spec.Name = "Snapshot",$_.VMname -join ' ' $spec.Description = "Take a snapshot of $($vm.Name)" $spec.Enabled = $true $spec.Notification = $emailAddr $spec.Scheduler = New-Object VMware.Vim.OnceTaskScheduler $spec.Scheduler.runat = $snapTime $spec.Action = New-Object VMware.Vim.MethodAction $spec.Action.Name = "CreateSnapshot_Task" @($snapName,$snapDescription,$snapMemory,$snapQuiesce) | %{ $arg = New-Object VMware.Vim.MethodActionArgument $arg.Value = $_ $spec.Action.Argument += $arg } $scheduledTaskManager.CreateObjectScheduledTask($vm.ExtensionData.MoRef, $spec) but I get the following error. I'm pretty new to scripting, so can someone please help me?: Cannot convert argument "obj", with value: "System.Object[]", for "CreateObjectScheduledTask" to type "VMware.Vim.ManagedObjectReference": "Cannot convert the "System.Object[]" value of type "System.Object[]" to type "VMware.Vim.ManagedObjectReference"." At \\MyServer\Folder1\Folder2\ScheduleSnapshots.ps1:43 char:1 + $scheduledTaskManager.CreateObjectScheduledTask($vm.ExtensionData.MoR ... + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : NotSpecified: (:) [], MethodException + FullyQualifiedErrorId : MethodArgumentConversionInvalidCastArgument