We have a number of time sensitive scheduled tasks based around in our enviroment. When we fire the scheduled tasks against the vCenter they are an hours later then in the powercli variable.
I checked the time on the hosts and VC server and they were correct, but the scheduled task's runtime was actually changed to an hour later. we have 6.7U3 running. does anybody have this experience also or know how to fix this..
any suggestions
I suspect that it is because you entered the time in local time.
The scheduled task expects the time in UTC.
But you can easily convert that, for example.
$onceScheduler.RunAt = (Get-Date '06/30/2020 17:00:00').ToUniversalTime()
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Hi LucD thanks for your reply.
If is use: ( if $snaplaunch = 08:00
$snapTime = (Get-Date $snaplaunch).ToUniversalTime() -> here $snaptime is 2 hours less 06:00
$snapTime = (Get-Date $snaplaunch).ToLocalTime() -> here $snaptime is 2 hours more 10:00
so we are closed but not yet there... are there other methods like ToUniversalTime() and ToLocalTime()
i saw out vCenter is CEST...
LucD btw we are located in the Netherlands GMT+1
The problem with your time-string is that you didn't specify which TZ that time is in.
See how Kind states 'unspecified'
[datetime]$snaplaunch | Select Kind,DateTime
By adding the TZ to the string, the DateTime cast will assume that this is your local time.
[datetime]$snaplaunch | Select Kind,DateTime
Now you just have to use the UTC method
([DateTime]$snaplaunch).ToUniversalTime() | Select Kind,DateTime
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
hi LucD, thanks for your reply. i used your script from a way back ;-), i copied it below.
How can i change it so it works ok with the timezone edit in the scheduled task?
in my case the date/time in your script like "10/11/18 23:00", i replaced it with the variable $snaplauch
###############
# These are the values you should get from your webform
#
$vmName = 'servername'
$snapTime = Get-Date "10/11/18 23:00"
$snapName = 'Test'
$snapDescription = 'Scheduled snapshot'
$snapMemory = $false
$snapQuiesce = $true
$emailAddr = 'xxx@xxx.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.MonthlyByWeekdayTaskScheduler
$spec.Scheduler.Offset = [VMware.Vim.WeekOfMonth]::second
$spec.Scheduler.Weekday = [VMware.Vim.DayOfWeek]::tuesday
$spec.Scheduler.Hour = 6
$spec.Scheduler.Interval = 1
$spec.Name = "Snapshot",$_.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)
The following is the easiest method (without entering the TZ).
And it takes Daylight Saving Time into account.
$t2 = Get-Date '01/11/2020 10:00'
([System.DateTimeOffset]::new($t1)).UtcDateTime
([System.DateTimeOffset]::new($t2)).UtcDateTime
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Hi LucD yes now it is working pitty that i can not force the 24H clock easy. but ok.
thanks again for your help.
How do you mean "... can not force the 24H clock easy"?
The default format (12 or 24) depends on the regional settings on your station.
Or do you mean in the Web Client?
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
ahhh yes , i just checked om the script machine it has Europe/Amsterdam 24h clock and now region set to US states -> netherlands. tomoorw test and come back on it.
thanks LucD. for you help..