Author Posts

February 20, 2018 at 3:20 am

I can not figure out how to convert the creationtime to normal time. Here is the output i get in excel file which is 2018-02-18T23:51:55. I would like to convert it before i sent it to csv file. Here is the current code i have . I even tried the comment out code and did not work

This is pulling multiple data and putting them in csv file.

    $startDate = (Get-Date).AddDays(-7).ToString('MM/dd/yyyy') 
    $endDate = (Get-Date).ToString('MM/dd/yyyy')
    $results = Search-UnifiedAuditLog -StartDate $startDate -EndDate $endDate  -UserIds $upn
$ConvertedOutput = $results | Select-Object -ExpandProperty AuditData | ConvertFrom-Json
$ConvertedOutput | Select-Object CreationTime,UserId,Operation,ResultStatus,ClientIP #| Export-Csv $OutputFile -NoTypeInformation -Append
 $ConvertedOutput | Export-Csv $OutputFile -NoTypeInformation
 
 #@{Name='CreationTime';Expression={Get-Date $_.CreationTime -Format 'MM\dd\yyyy'},

February 20, 2018 at 4:44 am

Why not just use .Net to convert it.

Just use .Net to covert it
[datetime]'2018-02-18T23:51:55'

Sunday, February 18, 2018 11:51:55 PM

[datetime]'2018-02-18T23:51:55' -f 'ddMMMyyyy'
02/18/2018 23:51:55

February 20, 2018 at 7:42 am

I will try that. i am almost there by using your information. Is there anyway not to have it military time ? It would be easier for my managers. I tried just date time but did not need the whole date .

This would be a good format just with normal time

[datetime]'2018-02-18T23:51:55' -f 'ddMMMyyyy'
02/18/2018 23:51:55

be this instead

02/18/2018 11:51 PM

Thank you so far for your help