formt txt to convert format dates and compare

This topic contains 3 replies, has 2 voices, and was last updated by  Taillez 1 week, 4 days ago.

  • Author
  • #101457



    I want to retrieve the warranty dates of my DELL server devices and compare them to the current date, then my powershell script send the result to my CENTREON (less than 90 days Warning, less than 30 days CRITICAL..etc ...)

    I found a script "GetDellWarrantyInfo.ps1"

    the script works well and I get the information "warranty date" in a variable.

    unfortunately I do not know how to process the information I get, I start powershell and I do not understand how to convert my result format date and then make the comparison with the date of the day.

    Do you have some tips to bring me to help me in my research?

    in advance a thank you to those who can help me.

    Best regards


  • #102182

    Don Jones

    I'm not able to run the code as I don't have a Dell, so I can't see what data you're actually getting back. If you could share some of that, it'd be easier to offer useful suggestions.

    Generally, if you're getting dates as a string, you want to convert them to a DateTime:

    [DateTime]$datetime = "03/04/2018"

    As an example. Get-Date also returns DateTimes:

    $Now = Get-Date

    And then you can compare using -gt (greater than) and -lt, or other comparison operators. Those all work against dates.

  • #102224


    thank-s for your help 🙂

  • #102227


    the script for


    # codes de sortie

    # "OK" exit 0
    # "WARN" exit 1
    # "CRIT" exit 2
    # "UNKNOW" exit 3

    # version de powershell V3

    #Build URL
    # "gwmi win32_bios | Select –ExpandProperty SerialNumber"
    $name = $args[1]

    $servicetag = $args[0]
    $URL1 = "$ServiceTag"
    $URL2 = "?apikey=fe0cae32-xxxxx-49a6-a570-xxxxxae38401"
    $URL = $URL1 + $URL2

    # Get Data
    $Request = Invoke-RestMethod -URI $URL -Method GET -contenttype 'Application/xml'

    # Extract Warranty Info
    $Warranty=$Request.AssetWarrantyDTO.AssetWarrantyResponse.AssetWarrantyResponse.AssetEntitlementData.AssetEntitlement|where ServiceLevelDescription -NE 'Dell Digitial Delivery'

    # Read first entry if available
    If ($Warranty -is [Object])
    $expiredate = $enddate.Substring(0,10)
    $lastdate = (Get-Date)
    $date = [System.datetime]$expiredate

    $tdiff = New-TimeSpan -Start $lastdate -End $date
    $Nb_jour = $tdiff.Days

    IF( $Nb_jour -gt "60" )
    write-host -foregroundcolor green "$name , sous garantie pendant encore $NB_jour jours , service TAG $servicetag" ;
    exit 0

    IF( $Nb_jour -gt "0" )
    write-host -foregroundcolor green "$name , sous garantie pendant encore $NB_jour jours , service TAG $servicetag" ;
    exit 1

    write-host -foregroundcolor red "$name , hors garantie depuis $NB_jour jours , service TAG $servicetag" ;
    exit 2

You must be logged in to reply to this topic.