對於一次性改變顯示的列,管道到select
或Format-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>
你拼錯CREATIONTIME還是你是否意味着將LastWriteTime替換爲CreatingTime? – dugas
是的,我想我做了 – silla