PowerShell script exchange
Post Reply
dalfa
Novice
Posts: 6
Liked: never
Joined: May 11, 2016 8:59 am
Full Name: Fabrizio
Contact:

Date in utc

Post by dalfa »

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
veremin
Product Manager
Posts: 20284
Liked: 2258 times
Joined: Oct 26, 2012 3:28 pm
Full Name: Vladimir Eremin
Contact:

Re: Date in utc

Post by veremin »

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.
dalfa
Novice
Posts: 6
Liked: never
Joined: May 11, 2016 8:59 am
Full Name: Fabrizio
Contact:

Re: Date in utc

Post by dalfa »

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
veremin
Product Manager
Posts: 20284
Liked: 2258 times
Joined: Oct 26, 2012 3:28 pm
Full Name: Vladimir Eremin
Contact:

Re: Date in utc

Post by veremin »

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.
dalfa
Novice
Posts: 6
Liked: never
Joined: May 11, 2016 8:59 am
Full Name: Fabrizio
Contact:

Re: Date in utc

Post by dalfa »

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

best regards,
Fabrizio
veremin
Product Manager
Posts: 20284
Liked: 2258 times
Joined: Oct 26, 2012 3:28 pm
Full Name: Vladimir Eremin
Contact:

Re: Date in utc

Post by veremin »

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.
Post Reply

Who is online

Users browsing this forum: No registered users and 16 guests