KelvinTegelaar / PowerShellWarrantyReports

a repo dedicated to automatic warranty reporting and retrieval from different systems such as IT-Glue, Connectwise, Autotask, and N-central.
GNU Affero General Public License v3.0
173 stars 71 forks source link

HP Error Convert Date #55

Closed schenardie closed 2 years ago

schenardie commented 2 years ago

Hi Kelvin, upon using a valid HP serial which probably HP does not source warranty information for the HP api returns the data with serial number and all the other fields with $null. Then when the function tries to convert start date (because it doesnt exists) it throws an error

Cannot convert null to type "System.DateTime".
At C:\Program Files\WindowsPowerShell\Modules\PSWarranty\1.7.1\private\Get-HPWarranty.ps1:12 char:30
+ ...      $WarrantyState = if ([DateTime]$HPReq.endDate -le $today) { "Exp ...
+                               ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidArgument: (:) [], RuntimeException
    + FullyQualifiedErrorId : nullToObjectInvalidCast

Cannot convert null to type "System.DateTime".
At C:\Program Files\WindowsPowerShell\Modules\PSWarranty\1.7.1\private\Get-HPWarranty.ps1:13 char:9
+         $WarObj = [PSCustomObject]@{
+         ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidArgument: (:) [], RuntimeException
    + FullyQualifiedErrorId : nullToObjectInvalidCast

I've changed the function to only try to convert the dates if startdate is not empty.

KelvinTegelaar commented 2 years ago

Nice, thanks.