Hi
Thank you for you reply, you are spot on i do need to the snapshot to run at 11:30pm. Just to summarise
- We have one VCentre in UK
- We have site in US, India, Australia, UK
- We have over 1500 vm and Admin will run task from their own PC (in US, India, Australia) to setup the snapshot for 11:30pm on tues as example
Based on you reply i would need a script for each site that will like this(is there way to have one script that will do this?).
I would need to change the time zone ...."Eastern Standard Time". on each script
Script would look like this
$vmName = 'MyVM'
$snapTime = Get-Date "31/10/16 23:00"
# Get the target timezone
$cstzone = [System.TimeZoneInfo]::FindSystemTimeZoneById("Eastern Standard Time")
# Get the UTC time for 11:30 in the target timezone
$cstTime = $snaptime.AddHours(-$cstzone.BaseUtcOffset.TotalHours)
$snapName = 'Test'
$snapDescription = 'Scheduled snapshot'
$snapMemory = $false
$snapQuiesce = $true
$emailAddr = 'lucd@lucd.info'
$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)