2012-09-26 30 views
5

如果你使用Get-ChildItem你喜歡的東西Get-ChildItem與CreationTime而不是LastWriteTime?

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 

多數民衆贊成罰款。我只想現在將LastWriteTime輸出更改爲CreationTime。其他一切應該是一樣的。有任何想法嗎?

+0

你拼錯CREATIONTIME還是你是否意味着將LastWriteTime替換爲CreatingTime? – dugas

+0

是的,我想我做了 – silla

回答

3

您可以選擇它與Select-Object或任何Format-*小命令

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

如果你的意思是,你想顯示屬性創建時間,而不是LastWriteTime,那麼你可以管得到-ChildItem的輸出選擇,對象,並指定要選擇哪個屬性:

Get-ChildItem | Select Mode, CreationTime, Length, Name 
4

對於一次性改變顯示的列,管道到selectFormat-Table的是最簡單的。如果您希望將其作爲一個持久性更改,則需要處理支配PowerShell如何顯示文件系統對象的格式文件。

不推薦編輯現有的格式文件(可能在$env:SystemRoot\system32\WindowsPowershell\v1.0\FileSystem.format.ps1xml),因爲該文件底部有一個簽名塊。更改文件內容將使簽名無效,這可能會導致問題。

相反,您可以定義自己的格式文件,它將覆蓋默認格式文件。下面的文件保存爲FileFormat.format.ps1xml和運行

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

默認情況下,CreationTime將顯示,沒有LastWriteTime

格式文件的內容(從real格式文件複製,只是改變了相關位):

<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> 
+0

很好的信息。 – dugas

2

在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