2

While trying to create a report compatible with the SPE Data Importer, I noticed that the date is formatted rather than the raw value.

How do I change this script to give me the date in the proper format?

$templateId = "{76036F5E-CBCE-46D1-AF0A-4143F9B557AA}"
Get-Item -Path master: -Query "/sitecore/content/Home//*[@@templateid='$($templateId)']"  | 
    Show-ListView -Property ID, Name, __Created, FullPath

Sample Report

1 Answer 1

5

Fun Fact: SPE adds properties to items returned by Get-Item and Get-ChildItem (referred to as automatic properties. With automatic properties your code can change from $item.Fields["Title"].Value to $item.Title.

Since we want the raw version of the field, we will need to populate the report using the raw field. In the standard Sitecore API you can access the raw field using the Fields collection.

Example: The following access the raw field value.

$item.Fields["Title"]

Example: The following demonstrates the changes to the script to access the raw values (denoted by $_.Fields["FIELDNAME"]).

$templateId = "{76036F5E-CBCE-46D1-AF0A-4143F9B557AA}"
Get-Item -Path master: -Query "/sitecore/content/Home//*[@@templateid='$($templateId)']"  | 
    Show-ListView -Property ID,Name, @{name="__Created";expression={$_.Fields["__Created"]}},FullPath

Fixed

Note: Incase you were curious, the datetime properties are formatted with the command [Sitecore.DateUtil]::IsoDateToDateTime().

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.