Date in utc

PowerShell script exchange

Date in utc

Veeam Logoby dalfa » Wed Feb 01, 2017 3:53 pm

Hello,

I'm trying to get job time in utc, in order to compare events between veeam b&r and guest machines but all the so-called xxxxxUTC entities seem to always report the localized datetime, eg.
Code: Select all
PS C:\Users\changemanager> (get-date).ToUniversalTime()
Wednesday, February 01, 2017 3:47:34 PM

PS C:\Users\changemanager> get-date
Wednesday, February 01, 2017 11:47:37 AM

PS C:\Users\changemanager>  Get-VBRBackupSession|select -last 1 |select CreationTime, CreationTimeUTC

CreationTime                                                 CreationTimeUTC                                           
------------                                                 ---------------                                           
1/17/2017 3:45:13 AM                                         1/17/2017 3:45:13 AM

Where am I going wrong?

thanks and regards,
Fabrizio
dalfa
Novice
 
Posts: 6
Liked: never
Joined: Wed May 11, 2016 8:59 am
Full Name: Fabrizio

Re: Date in utc

Veeam Logoby v.Eremin » Thu Feb 02, 2017 1:58 pm

Chances are, there is some bug affecting in time reflection logic. The fix is simple, though, just leverage ToUniversalTime() method:

Code: Select all
$Session = Get-VBRBackupSession | sort creationtime -Descending | select -first 1
$Session.CreationTime.ToUniversalTime()

Thanks.
v.Eremin
Veeam Software
 
Posts: 13558
Liked: 1006 times
Joined: Fri Oct 26, 2012 3:28 pm
Full Name: Vladimir Eremin

Re: Date in utc

Veeam Logoby dalfa » Fri Feb 03, 2017 2:01 pm

Hi Vladimir,

Great, it works! I tried
Code: Select all
  (Get-VBRBackupSession | select -last 1 | select-object CreationTime) .ToUniversalTime ()
but I was not fully aware of select-object behaviour.. so, I have to explicitly use variables instead of piping to select-object.

thanks and regards,
Fabrizio
dalfa
Novice
 
Posts: 6
Liked: never
Joined: Wed May 11, 2016 8:59 am
Full Name: Fabrizio

Re: Date in utc

Veeam Logoby v.Eremin » Fri Feb 03, 2017 2:07 pm

Yep, you can use select cmdlet this way. If you want to get the latest session of particular job, you can add a job name as filter option:

Code: Select all
$Session = Get-VBRBackupSession | where {$_.name -like "*Name of your backup job*"}| sort creationtime -Descending | select -first 1
$Session | select name, {$_.creationtime.touniversalTime()}


Thanks.
v.Eremin
Veeam Software
 
Posts: 13558
Liked: 1006 times
Joined: Fri Oct 26, 2012 3:28 pm
Full Name: Vladimir Eremin

Re: Date in utc

Veeam Logoby dalfa » Tue Feb 07, 2017 4:40 pm

Great! Today, too, I Learned Something New :D

best regards,
Fabrizio
dalfa
Novice
 
Posts: 6
Liked: never
Joined: Wed May 11, 2016 8:59 am
Full Name: Fabrizio

Re: Date in utc

Veeam Logoby v.Eremin » Wed Feb 08, 2017 7:12 pm

Trust me - there is a lot to learn in PowerShell. No once will it be able to surprise you.

Glad to hear that my input has been helpful for you.
v.Eremin
Veeam Software
 
Posts: 13558
Liked: 1006 times
Joined: Fri Oct 26, 2012 3:28 pm
Full Name: Vladimir Eremin


Return to PowerShell



Who is online

Users browsing this forum: Bing [Bot] and 14 guests