title: PowerShell Script to delete a folder in a Visual Studio Project with EnvDTE
body: <p>Using PowerShell I am trying to remove a specific sub-folder from my project using <a href="https://docs.microsoft.com/en-us/dotnet/api/envdte?view=visualstudiosdk-2017" rel="nofollow noreferrer">EnvDTE</a>.</p>
  
  <p>The folder I want to remove is:</p>
  
  <blockquote>
    <p>MyWebProject\Assets\FolderToDelete</p>
  </blockquote>
  
  <p>And the script I have started with is:</p>
  
  <pre><code>$DTE.Solution.Projects|Where-Object{$_.Name -eq 'MyWebProject'}|Select-Object -Expand ProjectItems
  </code></pre>
  
  <p>Using a loop, I then traverse <code>ProjectItems</code> to find "FolderToDelete" (of type <code>ProjectItem</code>). I then call <a href="https://docs.microsoft.com/en-us/dotnet/api/envdte.projectitem.remove?view=visualstudiosdk-2017" rel="nofollow noreferrer">ProjectItem.Remove</a> as well as delete it from disk:</p>
  
  <pre><code>$folderToDelete.Remove()
  $folderToDeletePath = $folderToDelete.Remove.Properties.Item("FullPath").Value
  Remove-Item -path $folderToDeletePath -recurse
  $project.Save()
  </code></pre>
  
  <p>In the Visual Studio solution explorer, I have "Show All Files" turned on and I can see that "FolderToDelete" is removed from the project, but the solution explorer still shows it as being it on disk, but it has actually been deleted (it goes away if I click "refresh" in the solution explorer"). </p>
  
  <p><a href="https://i.stack.imgur.com/xFJ9K.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/xFJ9K.png" alt="enter image description here"></a></p>
  
  <p>This causes some issues for me as Visual Studio still seems to think it is on disk.</p>
  
  <p>Using EnvDTE, how can I get Visual Studio to refresh and acknowledge this deletion?</p>