I would like to add a schedule task for taking snapshots at certain dates and times from a list of VM's . I only know how to do this individually. VM's would use $vmName and Date and time would use $snapTime This list would be in a CSV format using the Variables NAME, DATE, TIME Name Date Time VM1 03/04/2019 22:00 VM2 03/04/2019 22:01 VM3 03/04/2019 22:02 Would anyone know how could I incorporate this into the script below Thanks ############### # Enter Values $vmName = 'SERVERNAME' $snapTime = Get-Date "03/04/2019 16:58" $snapName = 'CLI Script - Pre Patch' $snapDescription = 'Scheduled Test CLI Script Snapshot' $snapMemory = $false $snapQuiesce = $true $emailAddr = '11111@11111.com' ############### $vm = Get-VM -Name $vmName $si = get-view ServiceInstance $scheduledTaskManager = Get-View $si.Content.ScheduledTaskManager $spec = New-Object VMware.Vim.ScheduledTaskSpec $spec.Scheduler = New-Object VMware.Vim.OnceTaskScheduler $spec.Scheduler.runat = $snapTime $spec.Name = "CLI Script", $VMname -join ' ' $spec.Description = "Take a snapshot of $($vm.Name)" $spec.Enabled = $true $spec.Notification = $emailAddr $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)
↧