title: Is Get-ChildItem -Recurse broken when there are square brackets in the input path?
body: <p>OK, so I feel like this <em>must</em> be a bug in PowerShell, but I wanted to see if you guys think this sounds broken. It's quite an easy thing to reproduce, but I can see why it might not be a particularly common use case. The steps I've put below aren't actually what my script was doing, I was actually calculating sizes of subfolders - I've just condensed it down to the simplest possible scenario that shows my problem.</p>
  
  <p>I have only tried this on PowerShell 5.0.10240.16384, but might soon have the chance to test it on an earlier version [<strong>Edit:</strong> I have now tested this on PowerShell 2.0, and the bug does <strong>not</strong> appear in that version - it works as expected]. Just a quick note - I've used <code>gci</code> throughout as an abbreviation for Get-ChildItem. If you didn't already know, this works to actually type into PowerShell too. But the problem exists whatever alias you use.</p>
  
  <p>First, create a folder called <code>Test [123]</code> somewhere handy. In that folder, create a couple of files. Mine are caled <code>Test1.txt</code> and <code>Test2.txt</code>. They don't need to have anything in them.</p>
  
  <p>Next, open a PowerShell session and <code>Set-Location</code> to the <em>parent folder</em> of your new <code>Test [123]</code> folder.</p>
  
  <p>Now, run <code>gci -Filter Test*</code> and you should see something like:</p>
  
  <pre><code>Mode                LastWriteTime         Length Name
  ----                -------------         ------ ----
  d-----       11/15/2015   3:22 PM                Test [123]
  </code></pre>
  
  <p>All good, right? Next, try <code>gci -Filter Test* | gci</code>. This makes the output of the first gci the input for the next one, ie shows us the children of each item the first gci returns. This gives us the following:</p>
  
  <pre><code>Mode                LastWriteTime         Length Name
  ----                -------------         ------ ----
  -a----       11/14/2015  10:21 PM              0 Test1.txt
  -a----       11/15/2015   3:55 PM              0 Test2.txt
  </code></pre>
  
  <p>Again, all good - exactly as expected. This is all the files from our <code>Test [123]</code> folder.</p>
  
  <p>Now try this: <code>gci -Filter Test* | gci -Recurse</code>. All we've changed is that the second call to <code>gci</code> is now recursive, so it should show us all files including subfolders. We don't have any subfolders, so we're expecting the same results, right?</p>
  
  <p>Wrong. We don't get any output at all. Seems very odd that all we've done is added <code>-Recurse</code> and now we get different output. I think that adding <code>-Recurse</code> should never render <em>less</em> output, only ever more.</p>
  
  <p>Here's the next weird thing. Now try <code>gci -Filter Test* | gci -Recurse -Name</code>. This is the same as before except with the <code>-Name</code> parameter added. This is simply saying that we want the same output, except we only want the filenames and not the full information about each item. So we're probably expecting nothing back. But that's not what we get, we get this:</p>
  
  <pre><code>Test1.txt
  Test2.txt
  </code></pre>
  
  <p>This has <em>got</em> to be broken, right? Firstly <code>-Recurse</code> should never reduce the amount of output, and secondly asking for the output in a different format should not change the amount of output we get.</p>
  
  <p>This only happens when there are square brackets in the name of the folder. If you create another folder, just called <code>Test</code>, and run all the commands above again, you will always see the files from the <code>Test</code> folder.</p>
  
  <p>My research lead me to the <code>-LiteralPath</code> parameter; however, rephrasing the above command as <code>gci -Filter Test* | foreach { gci -Recurse -LiteralPath $_ }</code>, so as to use that parameter, still returns no output, and again, adding the <code>-Name</code> parameter starts the files being returned again.</p>
  
  <p>I've managed to do a workaround for this, using the <code>-Name</code> parameter and then combining it with the path of the folder I'm searching, then passing that into <code>Get-Item</code>, but that's made the code longer and uglier than it needs to be.</p>
  
  <p>So my question is, have I made a mistake or misunderstood something? Or is this a bug I should report?</p>