Software Development Kit (SDK) and API Discussions

Get-NcSnapMirror LastTransferEndTimestamp to Date

brad2020
2,503 Views

Couple things with this, first I'm wanting to convert the output from LastTransferEndTimestamp to a human readable date.  I've read a few articles that demonstrate how to convert the output using get-date and I've had good success but I'm struggling to get the syntax correct to make the conversion on single line nested in foreach loop.

 

No struggles here

PS C:\> $date = (Get-Date '1970-01-01').AddSeconds(1471979101)
PS C:\> $date.GetDateTimeFormats('s')
2016-08-23T19:05:01

My questions, how  can I achieve the desired result with the code below?  I like the flexibility of using the code below but, am I over complicating it? 

 

I struggle here.

$mirrors = @()

foreach ($controller in @($controllers)) {
Connect-NcController $controller
# Collect desired volumes from controllers and store in variable
$mirrors += Get-NcSnapmirror -Controller $_ | Where-Object {$_.DestinationVolume -match 'Prod_SQL'}
} #foreach
$reportData = foreach ($mirror in $mirrors) {
    # Create object with values
    [PSCustomObject][ordered]@{
        'Destination_SVM'     = $mirror.DestinationVserver
        'Destination_Vol'           = $mirror.DestinationVolume 
        'Status'           = $mirror.status 
        'LagTime'           = $mirror.LagTime
        'LastTransDuration'     = $mirror.LastTransferDuration
        'LastTransSize_GB'          = $mirror.LastTransferSize / 1tb | % {$_.ToString("#.##")}
        'LastTransError'        =$mirror.LastTransferError
        'LastTransEnd'        =$mirror.LastTransferEndTimestamp
        'TranferRateMax'        =$mirror.CurrentMaxTransferRate
        'ExportSnapshot'        =$mirror.ExportedSnapshot
        'SnapshotTimestamp'        =$mirror.CurrentMaxTransferRateExportedSnapshotTimestamp
        'Break/fail'      = $mirror.BreakFailedCount
        'CatalogStatus'  = $mirror.CatalogStatus;
         

    }
}

Thanks in advance

1 ACCEPTED SOLUTION

donny_lang
2,473 Views

Replacing line 18 in your code with this:

 

 (Get-Date '1970-01-01').AddSeconds($mirror.LastTransferEndTimestamp)

worked in my lab, and yielded output like this:

 

LastTransEnd      : 2/25/2020 7:05:16 AM

View solution in original post

3 REPLIES 3

donny_lang
2,474 Views

Replacing line 18 in your code with this:

 

 (Get-Date '1970-01-01').AddSeconds($mirror.LastTransferEndTimestamp)

worked in my lab, and yielded output like this:

 

LastTransEnd      : 2/25/2020 7:05:16 AM

brad2020
2,463 Views

Worked perfectly.  Any advice on lag time to represent dd:hh:ss ?

donny_lang
2,457 Views

Line 14 to the right of the equal sign can be replaced with:

 

[Timespan]::FromSeconds($mirror.LagTime) | % {"{0:dd\:hh\:mm\:ss}" -f $_}

It displays like this:

 

LagTime           : 00:09:35:31
Public