Microsoft Virtualization Discussions

Trying to use get-natime into a variable

ramjet666
5,103 Views

Hi,

I am trying to get the current system time into a variable.

If I run get-natime I get:

Name                           Value
----                           -----
UtcTime                        1299518447
LocalTimeDT                    07/03/2011 17:20:47
UtcTimeDT                      07/03/2011 17:20:47
LocalTime                      1299518447

This is as expected.

what I want is LocalTimeDT in a variable but the command:

get-natime | where-object {$_.Name -eq "LocalTimeDT"}

Does not return any data.

How can I get 'LocalTimeDT" in to a variable?

1 ACCEPTED SOLUTION

beam
5,103 Views

Have you tried (Get-NaTime).LocalTimeDT?

It appears to work for me:

PS C:\Users\SBeam> (Get-NaTime).LocalTimeDT
Monday, March 07, 2011 6:08:44 PM

***EDIT***

It looks like you may be using an older version of the toolkit where Get-NaTime returns a hashtable.  In that case, the command (Get-NaTime).Item("LocalTimeDT") should do the trick.

Hope that helps!

Steven

View solution in original post

5 REPLIES 5

beam
5,104 Views

Have you tried (Get-NaTime).LocalTimeDT?

It appears to work for me:

PS C:\Users\SBeam> (Get-NaTime).LocalTimeDT
Monday, March 07, 2011 6:08:44 PM

***EDIT***

It looks like you may be using an older version of the toolkit where Get-NaTime returns a hashtable.  In that case, the command (Get-NaTime).Item("LocalTimeDT") should do the trick.

Hope that helps!

Steven

ramjet666
5,103 Views

Steven,

Excellent the first answer works, my powershell knowledge needs improving! I tried to work it out by googling but it let me down

ramjet666
5,103 Views

Hi,

We are now on BST time and the time from powershell (get-natime).localtimedt is an hour slow.

The time from a telnet session to the filer is correct and displays BST time.

Is they any way to get the BST time from the filer or is it a case of correcting it in powershell during summer months?

Thx.

beam
5,104 Views

It looks to me like this may be a bug in the way the time is reported to the toolkit.  You can either add an hour to the time reported, or more generally:

PS C:\Users\Administrator> $time = Get-NaTime
PS C:\Users\Administrator> $time.LocalTimeDT.AddSeconds($time.LocalTime-$time.UtcTime)

Should get you to the correct time.

Hope that helps,

Steven

beam
5,104 Views

We have been able to verify that this is in fact a bug in the API.  We are preparing a fix for the Get-NaTime cmdlet so that the correct local and UTC times are reported--look out for it in the next toolkit release.

Thank you for bringing this to our attention.

-Steven

Public