KelvinTegelaar / PowerShellWarrantyReports

a repo dedicated to automatic warranty reporting and retrieval from different systems such as IT-Glue, Connectwise, Autotask, and N-central.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Date Comparison not Working

jschpp opened this issue · comments

$WarrantyState = if ($warlatest -le $today) { "Expired" } else { "OK" }

The above comparison seems to break on my side:

Get-Warrantyinfo -DeviceSerial PC1QP2AJ

Serial                : ***REDACTED***
Warranty Product name : 1YR Battery (Carry-in/Depot Warranty)
                        3Y Depot, 9X5 2BD Warranty
                        3Y On-site, 9X5
StartDate             : 13.01.2021 00:00:00
EndDate               : 12.01.2024 00:00:00
Warranty Status       : Expired
Client                :

As you can see the Warranty date lies in the future but the Warranty Status still says Expired
Looking at the API this seems to be a problem when comparing the dates since the Req.EndDate is a culture sensitive string.

C:\Users\jschpp> $Req | fc

class PSCustomObject
{
  Serial = ***REDACTED***
  WarProduct = 1YR Battery (Carry-in/Depot Warranty)
  3Y Depot, 9X5 2BD Warranty
  3Y On-site, 9X5
  StartDate = 01/13/2021 00:00:00
  EndDate = 01/12/2024 00:00:00
}

C:\Users\jschpp> $Req.EndDate.GetType()

IsPublic IsSerial Name                                     BaseType
-------- -------- ----                                     --------
True     True     String                                   System.Object

Maybe this function should use Get-Date to parse the Date in before comparing for the expiration status.

C:\Users\jschpp> $PSVersionTable

Name                           Value
----                           -----
PSVersion                      7.1.3
PSEdition                      Core
GitCommitId                    7.1.3
OS                             Microsoft Windows 10.0.19042
Platform                       Win32NT
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1
WSManStackVersion              3.0

Absolutely right. I've been doing some date messing and seem to have missed this one. Will be fixed by next release.

Absolutely right. I've been doing some date messing and seem to have missed this one. Will be fixed by next release.

Thank you 👍

Resolved. 👍