Exchange Tip: Comparison of time span values


I needed to compare database copies with lagged time bigger than 0. It doesnt work to compare this way:

$database = Get-MailboxDatabase |select *
$lagged = $database | select * -ExpandProperty ReplayLagTimes | where {$_.value -ne "0.00:00:00"}

The reason is, that ReplyLagTime is of class TimeSpan. To compare it we must compare with the object of the same class. In my case I made variable of class TimeSpan and then compared.

$database | Select -ExpandProperty ReplayLagTimes | SELECT VALUE | GET-MEMBER

   TypeName: Selected.System.Collections.Generic.KeyValuePair`2[Microsoft.Exchange.Data.Directory.ADObjectId,Microsoft.
Exchange.Data.EnhancedTimeSpan]

Name        MemberType   Definition
----        ----------   ----------
Equals      Method       bool Equals(System.Object obj)
GetHashCode Method       int GetHashCode()
GetType     Method       type GetType()
ToString    Method       string ToString()
Value       NoteProperty Microsoft.Exchange.Data.EnhancedTimeSpan Value=00:00:00

Solution:

$a = New-TimeSpan
$a

Days              : 0
Hours             : 0
Minutes           : 0
Seconds           : 0
Milliseconds      : 0
Ticks             : 0
TotalDays         : 0
TotalHours        : 0
TotalMinutes      : 0
TotalSeconds      : 0
TotalMilliseconds : 0

Result:

$database | Select  -ExpandProperty ReplayLagTimes | where {$_.value -ne $a}
Key                                                         Value
---                                                         -----
EX13NODE1                                                   1.00:00:00

$database | Select  -ExpandProperty ReplayLagTimes | where {$_.value -eq $a}
Key                                                         Value
---                                                         -----
EX13NODE2                                                   00:00:00
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s