Split date time into seperate variables

This topic contains 2 replies, has 3 voices, and was last updated by Profile photo of Rob Simmers Rob Simmers 1 year, 4 months ago.

  • Author
  • #26732
    Profile photo of Graham Beer
    Graham Beer


    I'm checking the date of when some certificates expiry. The main part is:

    gci -path cert: -Recurse).GetExpirationDateString()

    I can split it fine by .split(' '), but i want all the dates separate. Any ideas ?


  • #26733
    Profile photo of Matt Bloomfield
    Matt Bloomfield

    I can't get the method working but using a string as an example, you could do something like this:

    $dateString = '23/06/2015 12:36:00'
    $date = ($dateString -split ' ')[0]
    $time = ($dateString -split ' ')[1]
  • #26737
    Profile photo of Rob Simmers
    Rob Simmers

    Try something like this:

    gci -path cert: -Recurse | Select Name, @{Label="ExpirationDate";Expression={$_.GetExpirationDateString()}}

    If that doesn't work, you may need to use foreach logic, like this

    $results = gci -path cert: -Recurse | foreach{ New-Object -TypeName PSObject -Property @{Name=$_.Name;ExpirationDate=$_.GetExpirationDateString()} }

You must be logged in to reply to this topic.