This project is read-only.

column titles on "dir"

Jun 25, 2014 at 3:59 PM
In several cases I have used "dir" as below:
§ DTE:\windows>dir
    Location: StudioShell.Provider\PSDTE::windows
    Available Operations: d  <      
           Visible Floating AutoHide               Type Name                               
---------- ------- -------- --------               ---- ----                               
d  <     i            *                      ToolWindow Autos                              
d  <     i            *                      ToolWindow Call Stack                         
d  <     i    *                              ToolWindow Class View                         
...
I use "Get-Member" to discover some other property I am interested in. I try to bring the two pieces of information together:
§ DTE:\windows>dir | select name, objectkind

name                                                                                       ObjectKind                                                                                
----                                                                                       ----------                                                                                
                                                                                           {F2E84780-2AF1-11D1-A7FA-00A0C9110051}
                                                                                           {0504FF91-9D61-11D0-A794-00A0C9110051}
                                                                                           {C9C0AE26-AA77-11D2-B3F0-0000F87570EE}
...
It turns out in this case that "caption" was the property displayed as "name" by "dir". In another case it was a different property that was displayed by dir as "name". Is this is a powershell-ism? I'm afraid I'm not a powershell power-user. How do the properties chosen for display by dir?

JR
Jun 27, 2014 at 12:40 PM
It turns out that the control of how "dir" works is not in the code. In the directory StudioShell\studioshell.provider\Formats, there is a collection of .ps1xml files. These configure how "dir" works. For example, the file "Window.Formats.ps1xml" controls how "dir" works in dte:\windows. There are two entries for each column, a header entry and a data entry. Here I show the entries for the column "Name":
...
<TableColumnHeader>
  <Label>Name</Label>
  <Alignment>left</Alignment>
  <Width>35</Width>
</TableColumnHeader>
...
<TableColumnItem>
  <ScriptBlock>$_.PSChildName,$_.Caption | select -first 1</ScriptBlock>
</TableColumnItem>
...
From this it's apparent that the column labeled "Name" for a window is actually a composite of PSChildName and Caption. To get what I expected to get above I should have used:
dir | select @{Name="Name"; Expression = {$_.PSChildName,$_.Caption | select -first 1}}, objectkind
If you are willing willing to rip off that tape that says "Do Not Open—No User Serviceable Parts Inside", you can change the way that "dir" works by editing these files. I don't know if there's a way of doing this on a per-user (or even per-solution?) basis; I'm not a powershell maven. Doing so probably voids your warranty, so make a backup copy first.

JR