title: Powershell script to list all open Explorer windows
body: <p><a href="https://stackoverflow.com/questions/31347905/get-report-of-all-open-explorer-windows">This question</a> shows a Powershell script to generate a list of open File Explorer windows and their path. 
  My goal is to capture the currently open set of explorer windows, and write out a CMD file with commands like: C:\WINDOWS\explorer.exe /e, "C:\open\this\folder"</p>
  
  <p>So I would like to have the full path and folder name in normal path notation. This is what is showing in titlebar of the Explorer Windows: "C:\open\this\Favorite folder"</p>
  
  <p>The proposed code is:</p>
  
  <pre><code>function Get-WindowTitle($handle) {
    Get-Process |
      Where-Object { $_.MainWindowHandle -eq $handle } |
      Select-Object -Expand MainWindowTitle
  }
  
  $app = New-Object -COM 'Shell.Application'
  $app.Windows() |
    Select-Object LocationURL, @{n='Title';e={Get-WindowTitle $_.HWND}}
  </code></pre>
  
  <p>As shown above, LocationURL provides a full path in an escaped-URL style: </p>
  
  <pre><code>file:///C:/open/this/Favorite%20%folder"
  </code></pre>
  
  <p>The @{n='Title';e={Get-WindowTitle $_.HWND}} component produces a column "Title"  which is truncated to 5 characters:</p>
  
  <pre><code>C:\...
  </code></pre>
  
  <p>The full output for one explorer window looks like:</p>
  
  <pre><code>LocationURL                                                 Title
  -----------                                                 -----
  file:///C:/open/this/Favorite%20%folder                     C:...
  </code></pre>
  
  <p>I found I could avoid the truncation by padding the string 'Title' with many spaces. That string's width seems to determine the maximum width of the output.
  Still, I observe that only about 60% of the open explorer windows list a path. The rest are just a blank line. </p>
  
  <p>I tried "$app.Windows() | Select-Object LocationName", but the output only contains the Explorer folder name only, not the full path and folder that is displayed in the Explorer title. </p>
  
  <p>Another mystery is why the script runs so slowly. If I have 10 explorer windows open, the script runs for 30 seconds, taking about 3 seconds per path. </p>
  
  <p>For this script:</p>
  
  <pre><code>function Get-WindowTitle($handle) {
    Get-Process |
      Where-Object { $_.MainWindowHandle -eq $handle } |
      Select-Object -Expand MainWindowTitle
  }
  
  $app = New-Object -COM 'Shell.Application'
  $app.Windows() |
    Select-Object LocationName,@{n='              ------------Title----------------                                   ';e={Get-WindowTitle $_.HWND}}
  </code></pre>
  
  <p>This is the output (with some redacting with *** for privacy)</p>
  
  <pre><code>PS C:\E***&gt; .\OpenExplorer.ps1
  
  LocationName               ------------Title----------------
  ------------ ----------------------------------------------------------------------------------
  2019-07
  Ame****
  2019 Priv...
  2019-10-3... C:\E\Event Presentations\2019-10-31 Priv**********bcast
  E            C:\E
  5G Brief ... C:\E\Tech************ing\5G Brief (2018)
  36 Series...
  2019 DE* ... C:\E\16*****N\2019 DE*******************
  Newsletters  C:\E\Newsletters
  Reports      C:\E\Tech************ing\Reports
  2019-10-2... C:\E\16**********s\2019-10-29 *********************
  2019-11      C:\Data\Docs\Stand*********24\2019-11
  UB****
  Financial... C:\E\Financ************
  Expenses     C:\E\Internal\Expenses
  E            C:\E
  E***
  </code></pre>