Split date time into seperate variables


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 ?


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]

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()} }