Microsoft Virtualization Discussions

Time values represented as integers

benjstarratt
5,532 Views

First...great initial release of a powershell interface.  I have been pestering my NetApp team for one for the last year.  As I have started playing with it, I have noticed some things that are difficult to use.  As an example, the get-nasnapshot command's accesstime property has a type of System.Int64.  A date time value would have been much easier to work with.  I end up using code that looks ike this:

Get-NaVol myvolume | Get-NaSnapshot | select Name, @{Name="AccessTime"; Expression = {([datetime]"1/1/1970").AddSeconds($_.AccessTime).ToLocalTime()}}

Additionally, the NetApp.Ontapi.Filer.Snapshot.SnapshotInfo object doesn't relate back to a volume.  I would love to use a simple expression to find all snapshots older than 7 days on a filer (something that wsa easily doable using the CodePlex PoshOnTap project):

get-navol | get-nasnapshot | where-object {$_.AccessTime -lt (Get-Date).AddDays(-7)}) | sort AccessTime

Are there plans to release a v2 with more nice-to-haves?  Am I misunderstanding the best way to accomplish some of these tasks?

1 ACCEPTED SOLUTION

fjohn
5,533 Views

Hi Ben,

Thanks for your feedback.

Ah the joy of converting between Windows & Unix time and vica versa.  Yes it would be nice to a couple of time conversion functions.

The NetApp.Ontapi.Filer.Snapshot.SnapshotInfo object doesn't relate specifically to a volume by can be used for an aggregate snapshot as well.  Perhaps "ParentObjectName" that you could alias or something?  In the meantime, you might try piping the output of get-navol to a foreach, and in the foreach do you where clause...

J

View solution in original post

3 REPLIES 3

fjohn
5,534 Views

Hi Ben,

Thanks for your feedback.

Ah the joy of converting between Windows & Unix time and vica versa.  Yes it would be nice to a couple of time conversion functions.

The NetApp.Ontapi.Filer.Snapshot.SnapshotInfo object doesn't relate specifically to a volume by can be used for an aggregate snapshot as well.  Perhaps "ParentObjectName" that you could alias or something?  In the meantime, you might try piping the output of get-navol to a foreach, and in the foreach do you where clause...

J

fjohn
5,533 Views

Hi Ben

Here you go:

get-navol | foreach-object {$ParentName=$_.Name;get-nasnapshot $_.Name | add-member -membertype noteproperty -name ParentName -value $ParentName -passthru} | select ParentName
,Name,@{Name="AccessTime";Expression={[timezone]::CurrentTimeZone.ToLocalTime(([datetime]'1/1/1970').AddSeconds($_.AccessTime))}}

Displays:

ParentName                                                   Name                                                         AccessTime
----------                                                   ----                                                         ----------
vol0                                                         nightly.0                                                    6/9/2010 10:00:31 PM
vol0                                                         hourly.0                                                     6/9/2010 6:00:31 PM
vol0                                                         hourly.1                                                     6/9/2010 2:00:31 PM
vol0                                                         hourly.2                                                     6/9/2010 10:00:30 AM
vol0                                                         hourly.3                                                     6/9/2010 6:00:31 AM
vol0                                                         nightly.1                                                    6/8/2010 10:00:32 PM
vol0                                                         hourly.4                                                     6/8/2010 6:00:31 PM
vol0                                                         hourly.5                                                     6/8/2010 2:00:31 PM

I just add the property "ParentName" to each object output by get-nasnapshot, then add that property in my list of stuff to display with select.  Could it be better?  Probably; but for now it works.

Happy Scripting

J


cknight
5,533 Views

Ben, I've just posted Toolkit version 1.0.1 which adds a ConvertTo-DateTime cmdlet.  It's not as nice as having all the cmdlets return DateTime values, but for the time being it's a slight improvement on the solution above:

C:\PS> Get-NaSnapshot vol0 | ft Name,@{Name="AccessTime";Expression={ConvertTo-DateTime $_.AccessTime}}


    Name                                    AccessTime
    ----                                    ----------
    weekly.0                                6/14/2010 4:00:32 AM
    benson(0118045471)_vol0_svq-src.0       6/3/2010 9:14:47 PM
    hourly.0                                2/12/2009 12:00:16 PM
    hourly.1                                2/12/2009 8:00:15 AM
    nightly.0                               2/12/2009 12:00:16 AM
    hourly.2                                2/11/2009 8:00:16 PM
    hourly.3                                2/11/2009 4:00:16 PM
    hourly.4                                2/11/2009 12:00:16 PM
    hourly.5                                2/11/2009 8:00:16 AM
    nightly.1                               2/11/2009 12:00:31 AM
Public