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                                                                                
----                                                                                       ----------                                                                                
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?

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":
  <ScriptBlock>$_.PSChildName,$_.Caption | select -first 1</ScriptBlock>
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.