title: Delete broken link
body: <p>I need to delete all the content of a folder which may include broken links among others. The folder path is provided by a variable. Problem is that <code>PowerShell</code> fails to remove the broken links.</p>
  
  <pre><code>$folderPath = "C:\folder\"
  </code></pre>
  
  <p>Attempt 1:</p>
  
  <pre><code>Remove-Item -Force -Recurse -Path $folderPath
  </code></pre>
  
  <p>Fails with error:</p>
  
  <pre><code>Remove-Item : Could not find a part of the path 'C:\folder\brokenLink'.
  At line:1 char:1
  + Remove-Item -Force -Recurse -Path $folderPath
  + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
      + CategoryInfo          : WriteError: (C:\folder\brokenLink:String) [Remove-Item], DirectoryNot 
     FoundException
      + FullyQualifiedErrorId : RemoveItemIOError,Microsoft.PowerShell.Commands.RemoveItemCommand
  </code></pre>
  
  <p>Attempt 2:</p>
  
  <pre><code>Start-Job { cmd /c rmdir $folderPath }
  </code></pre>
  
  <p>Fails because <code>$folderPath</code> gets passed as is instead of its value:</p>
  
  <pre><code>Start-Job { cmd /c rmdir $folderPath } | select command
  
  Command                                                                                             
  -------                                                                                             
   cmd /c rmdir $folderPath                                                                           
  </code></pre>
  
  <p>Any suggestion besides using the <code>.NET</code> framework?</p>
  
  <p><strong>EDIT</strong><br>
  By broken link I'm referring to a folder which points to a previously mounted partition, that doesn't exist anymore. The folder is still available but when attempting to navigate into it this error occurs because the destination doesn't exist anymore:<br>
  Error:</p>
  
  <blockquote>
    <p>C:\folder\brokenLink refers to a location that is unavailable. It
    could be on a hard drive on this computer, or on a network. Check to
    make sure that the disk is properly inserted, or that you are
    connected to the Internet or your network, and then try again. If it
    still cannot be located, the information might have been moved to a
    different location.</p>
  </blockquote>