title: Is it possible to filter using Get-ChildItem -Name?
body: <p>In <a href="https://stackoverflow.com/q/56628221/9902555">one of the questions</a> I answered recently I found interesting answer which shouldn't be working but still was. The question was about how to find specific folder recursively by its name and <code>cd</code> to it.</p>
  
  <p>The <a href="https://stackoverflow.com/a/56628538/9902555">answer proposed by A guest who's called Redd</a> was:</p>
  
  <pre class="lang-bsh prettyprint-override"><code>Get-ChildItem -Path .\ -Name Folder -Recurse -Depth 10
  </code></pre>
  
  <p>As per the documentation of <a href="https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.management/get-childitem?view=powershell-6#parameters" rel="nofollow noreferrer">Get-ChildItem</a>, <code>-Name</code> parameter is supposed to be <code>SwitchParameter</code> type and is responsible for returning only name (<code>System.String</code>), instead of <code>System.Object</code>.</p>
  
  <p>How it's possible that the solution still works?</p>
  
  <hr>
  
  <h3>MCVE:</h3>
  
  <pre class="lang-bsh prettyprint-override"><code># cd C:\SO\56628221
  mkdir test, test1, test2, test3
  mkdir .\test2\folder
  Get-ChildItem -Path .\ -Name Folder -Recurse -Depth 10
  </code></pre>
  
  <p>Current output:</p>
  
  <pre><code>test2\folder
  </code></pre>
  
  <p>Expected output:</p>
  
  <pre class="lang-bsh prettyprint-override"><code>Get-ChildItem : A positional parameter cannot be found that accepts argument 'Folder'.
  </code></pre>
  
  <hr>
  
  <h3>What have I tried?</h3>
  
  <ol>
  <li>First I checked that <code>-Path</code> is the only positional parameter. Apparently it is: </li>
  </ol>
  
  <p><img src="https://i.stack.imgur.com/9OBK5.png" alt="Get-ChildItem -Path documentation"></p>
  
  <p>All the other params have <code>Position: Named</code>.</p>
  
  <ol start="2">
  <li>Then I tried to switch the arguments to something like this:</li>
  </ol>
  
  <pre class="lang-bsh prettyprint-override"><code>Get-ChildItem -Path .\ Folder -Name -Recurse -Depth 10
  </code></pre>
  
  <p>It was still working, so that was clear indication that what I'm passing to the cmdlet is not the value for <code>-Name</code>.</p>
  
  <ol start="3">
  <li>Last thing I supposed was that I just send array of strings to <code>-Path</code>. I tried to do this explicitely:</li>
  </ol>
  
  <pre class="lang-cs prettyprint-override"><code>[string[]]$a = '.\','Folder'
  $a.GetType()
  Get-ChildItem -Path $a -Name -Recurse -Depth 10
  
  # Output:
  PS C:\SO\56628221&gt; $a.GetType()
  
  IsPublic IsSerial Name                                     BaseType
  -------- -------- ----                                     --------
  True     True     String[]                                 System.Array
  
  
  PS C:\SO\56628221&gt; Get-ChildItem -Path $a -Name -Recurse -Depth 10
  test
  test1
  test2
  test3
  test2\folder
  Get-ChildItem : Cannot find path 'C:\SO\56628221\Folder' because it does not exist.
  At line:1 char:1
  + Get-ChildItem -Path $a -Name -Recurse -Depth 10
  + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
      + CategoryInfo          : ObjectNotFound: (C:\SO\56628221\Folder:String) [Get-ChildItem], ItemNotFoundException
      + FullyQualifiedErrorId : PathNotFound,Microsoft.PowerShell.Commands.GetChildItemCommand
  </code></pre>