VMware Cloud Community
khalilm
Contributor
Contributor

Help with Scheduled Snapshot Task using CSV

Hi

I am trying to setup a scheduled task orginally taken from (https://communities.vmware.com/thread/541573), we running ESXi 6.7 U3, the task is being created but the date/time is not being passed through. Any help appreciated

The CSV format is

VMName, Description, Date, Time

The script is

# CSV File Format

# VMName,Description

# VM1,Test1

##########################

$snapMemory = $false

$snapQuiesce = $true

$emailAddr = 'xxx@xxx.com

$fileName = 'C:\Temp\Scripts\snapshot.csv'

###############

Import-Csv -Path $fileName -UseCulture | %{

# Verify the scheduled task name is not already in use

    $vm = Get-VM -Name $_.VMName

    $si = get-view ServiceInstance

    $scheduledTaskManager = Get-View $si.Content.ScheduledTaskManager

    $spec = New-Object VMware.Vim.ScheduledTaskSpec

    $spec.Name = "Snapshot of",$vm.Name -join ' '

    $spec.Description = $_.Description

    $spec.Enabled = $true

    $spec.Notification = $emailAddr

    $spec.Scheduler = New-Object VMware.Vim.OnceTaskScheduler

    $spec.Scheduler.runat = $_.Date," ",$_.Time -join ''

    $spec.Action = New-Object VMware.Vim.MethodAction

    $spec.Action.Name = "CreateSnapshot_Task"

    @($spec.Name,$spec.Description,$snapMemory,$snapQuiesce) | %{

        $arg = New-Object VMware.Vim.MethodActionArgument

        $arg.Value = $_

        $spec.Action.Argument += $arg

    }

    $scheduledTaskManager.CreateObjectScheduledTask($vm.ExtensionData.MoRef, $spec)

}

20 Replies
khalil1974
Enthusiast
Enthusiast

Hi, it is strange i noticed this on the other issue you helped me with but this one i do not the button. I am using a chrome browser to access the forum

pastedImage_0.png

mayabe i will try to log off and log back in

0 Kudos