Lib/Formatting/MyCustomFileInfo.format.ps1xml

<?xml version="1.0" encoding="utf-8"?>
<!-- *******************************************************************
Based Off: https://blogs.sap.com/2018/07/31/symbolic-links-in-powershell-extending-the-view-format/
Taken from sample files used by the Windows PowerShell engine.
Modified formatting of directory output to include Symlinks and Hardlinks
******************************************************************** -->
<Configuration>
  <SelectionSets>
    <SelectionSet>
      <Name>FileSystemTypes</Name>
      <Types>
        <TypeName>System.IO.DirectoryInfo</TypeName>
        <TypeName>System.IO.FileInfo</TypeName>
      </Types>
    </SelectionSet>
  </SelectionSets>
  <!-- ################ GLOBAL CONTROL DEFINITIONS ################ -->
  <Controls>
    <Control>
      <Name>FileSystemTypes-GroupingFormat</Name>
      <CustomControl>
        <CustomEntries>
          <CustomEntry>
            <CustomItem>
              <Frame>
                <LeftIndent>4</LeftIndent>
                <CustomItem>
                  <Text AssemblyName="System.Management.Automation" BaseName="FileSystemProviderStrings" ResourceId="DirectoryDisplayGrouping"/>
                  <ExpressionBinding>
                    <ScriptBlock>$_.PSParentPath.Replace('Microsoft.PowerShell.Core\FileSystem::', '')</ScriptBlock>
                  </ExpressionBinding>
                  <NewLine/>
                </CustomItem>
              </Frame>
            </CustomItem>
          </CustomEntry>
        </CustomEntries>
      </CustomControl>
    </Control>
  </Controls>
  <!-- ################ VIEW DEFINITIONS ################ -->
  <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>LastWriteTime</Label>
            <Width>25</Width>
            <Alignment>right</Alignment>
          </TableColumnHeader>
          <TableColumnHeader>
            <Label>Length</Label>
            <Width>14</Width>
            <Alignment>right</Alignment>
          </TableColumnHeader>
          <TableColumnHeader>
            <Label>Name</Label>
          </TableColumnHeader>
        </TableHeaders>
        <TableRowEntries>
          <TableRowEntry>
            <Wrap/>
            <TableColumnItems>
              <TableColumnItem>
                <PropertyName>Mode</PropertyName>
              </TableColumnItem>
              <TableColumnItem>
                <ScriptBlock>
                  [String]::Format('{0,10} {1,8}', $_.LastWriteTime.ToString('d'), $_.LastWriteTime.ToString('t'))
                </ScriptBlock>
              </TableColumnItem>
              <TableColumnItem>
                <ScriptBlock>
                  if ($_ -is [System.IO.DirectoryInfo]) {''}
                  elseif ($_.Length) {(Convert-FileLength -Length $_.Length).ToString()}
                  else {$_.Length.ToString()}
                </ScriptBlock>
              </TableColumnItem>
              <TableColumnItem>
                <ScriptBlock>
                                   if(-not [string]::IsNullOrEmpty($_.Target) -and -not [string]::IsNullOrEmpty($_.LinkType))
                  {'{0} -({2})-> {1}' -f $_.Name,$_.Target,$_.LinkType}
                  elseif(-not [string]::IsNullOrEmpty($_.ResolvedTarget) -and -not [string]::IsNullOrEmpty($_.LinkType))
                  {'{0} -({2})-> {1}' -f $_.Name,$_.ResolvedTarget,$_.LinkType}
                  else {$_.Name}
                                </ScriptBlock>
              </TableColumnItem>
            </TableColumnItems>
          </TableRowEntry>
        </TableRowEntries>
      </TableControl>
    </View>
  </ViewDefinitions>
</Configuration>