Search code examples
windowspowershellpowershell-2.0powershell-3.0powershell-4.0

How to use Remove-Item -Confirm:$false -Force properly in Windows PowerShell


So, I am writing this script in PowerShell and I am required to delete a few files in APPDATA on Windows. I wrote this line of code and it doesn't remove the item silently. It asks for confirmation even after using $Confirm:false. How do I fix this issue?

My code:

Get-ChildItem -Path $env:APPDATA\"Microsoft\teams\blob_storage" | Remove-Item -Confirm:$false -Force

I get this unwanted confirmation box every time I run the script:

Screenshot of the confirmation box


Solution

  • Here is your modified code. I hope it will work for you.

    Get-ChildItem -Path $env:APPDATA\"Microsoft\teams\blob_storage" | Remove-Item -Recurse -Force