title: Powershell Remove-Item leaving Folders Behind
body: <p>So I want to clean up some of my users profiles on a nightly basis using the following "script"</p>
  
  <pre><code>Get-ChildItem 'F:\View\Profiles\' -Recurse -Force |
      Where-Object {$_.Directory -match 'F:\\View\\Profiles\\((\w*).V2)\\AppData\\Roaming\\Trillian\\users\\((\w*%\w*%\w*))\\logs\\(_CLOUD|ASTRA)'} |
      Remove-Item -Recurse -Force
  </code></pre>
  
  <p>This deletes all the log files but leaves behind the folder structure. Because of that I tried the following query.</p>
  
  <pre><code>Get-ChildItem 'C:\TestProfileClean' -Recurse -Force |
      Where-Object {(($_.Name -eq "logs" -and $_.Directory) -and $_.DirectoryName -match 'C:\\TestProfileClean\\(\w*.V2)\\AppData\\Roaming\\Trillian\\Users\\((\w*)%40(\w*)%2Ecom)' )} |
      Remove-Item -Recurse -Force
  </code></pre>
  
  <p>This ensures that the folder deleted is named "logs" it is a directory and the directory name is in this format.</p>
  
  <pre><code>C:\\TestProfileClean\\(\w*.V2)\\AppData\\Roaming\\Trillian\\Users\\((\w*)%40(\w*)%2Ecom)
  </code></pre>
  
  <p>The problem is when I run the second command it does not delete any files, if I cut off <code>$_.DirectoryName</code> then I get the following output.</p>
  
  <pre><code>Directory: C:\TestProfileClean\username.V2\AppData\Roaming\Trillian\users\username%40compcorp%2Ecom
  
  
  Mode                LastWriteTime         Length Name
  ----                -------------         ------ ----
  d-----       12/14/2016   9:56 AM                logs 
  </code></pre>
  
  <p>Which will delete what I want but isn't specific enough for me to be comfortable running it.</p>
  
  <p>What am doing wrong that is preventing folders from being deleted but the script will delete all non folder items.</p>