Get-ChildItem with CreationTime instead of LastWriteTime?

if you use Get-ChildItem, you get something like

Mode                LastWriteTime     Length Name
----                -------------     ------ ----
d----          3/1/2006   9:03 AM            Bluetooth Software
d---s         5/10/2006   8:55 AM            Cookies
d----          5/9/2006   2:09 PM            Desktop

Good. I just want to now change the output of LastWriteTime to CreationTime . Everything else should be the same. Any ideas?

+5
source share
4 answers

You can select it using Select-Objector any of the cmdletsFormat-*

Get-ChildItem | Select-Object Mode,CreationTime,Length,Name
+3
source

For one-time changes to the displayed columns, piping up to selector is Format-Tableeasiest. If you want to make this a permanent change, you need to deal with format files that determine how powershell renders file system objects.

(, $env:SystemRoot\system32\WindowsPowershell\v1.0\FileSystem.format.ps1xml) , . , .

, . FileFormat.format.ps1xml

Update-FormatData -Prepend c:\FileFormat.format.ps1xml

CreationTime, LastWriteTime.

( , ):

<Configuration>
    <SelectionSets>
        <SelectionSet>
            <Name>FileSystemTypes</Name>
            <Types>
                <TypeName>System.IO.DirectoryInfo</TypeName>
                <TypeName>System.IO.FileInfo</TypeName>
            </Types>
        </SelectionSet>
    </SelectionSets>
    <ViewDefinitions>
       <View>
            <Name>children</Name>
            <ViewSelectedBy>
                <SelectionSetName>FileSystemTypes</SelectionSetName>
            </ViewSelectedBy>
            <GroupBy>
                <PropertyName>PSParentPath</PropertyName> 
                <CustomControlName>FileSystemTypes-GroupingFormat</CustomControlName>  
            </GroupBy>
            <TableControl>
                <TableHeaders>
                   <TableColumnHeader>
                      <Label>Mode</Label>
                      <Width>7</Width>
                      <Alignment>left</Alignment>
                   </TableColumnHeader>
                    <TableColumnHeader>
                        <Label>CreationTime</Label>
                        <Width>25</Width>
                        <Alignment>right</Alignment>
                    </TableColumnHeader>
                    <TableColumnHeader>
                        <Label>Length</Label>
                        <Width>10</Width>
                        <Alignment>right</Alignment>
                    </TableColumnHeader>
                    <TableColumnHeader/>
                </TableHeaders>
                <TableRowEntries>
                    <TableRowEntry>
                        <Wrap/>
                        <TableColumnItems>
                            <TableColumnItem>
                                <PropertyName>Mode</PropertyName>
                            </TableColumnItem>
                            <TableColumnItem>
                                <ScriptBlock>
                                    [String]::Format("{0,10}  {1,8}", $_.CreationTime.ToString("d"), $_.CreationTime.ToString("t"))
                                </ScriptBlock>
                            </TableColumnItem>
                            <TableColumnItem>
                            <PropertyName>Length</PropertyName>
                            </TableColumnItem>
                            <TableColumnItem>
                                <PropertyName>Name</PropertyName>
                            </TableColumnItem>
                        </TableColumnItems>
                    </TableRowEntry>
                </TableRowEntries>
            </TableControl>
        </View>
    </ViewDefinitions>
</Configuration>
+4

, CreationTime LastWriteTime, Get-ChildItem Select-Object , :

Get-ChildItem | Select Mode, CreationTime, Length, Name
+3

V3 :

    PS III> # UNTESTED: if work...you can paste this in your profile
    PS III>
    PS III> Update-TypeData -TypeName System.IO.FileInfo,System.IO.DirectoryInfo -MemberName DFPR DefaultDisplayPropertySet Mode,CreationTime,Length,Name
+2

All Articles