Use Powershell to Delete File

Using PowerShell commnads to delete a file

Example


    # Using PowerShell commnads to delete a file
    Remove-Item -Path "C:\test\FirstCreateFile.txt"
    

Copy and Try it


You can also use wildcard '*' characters to remove multiple items. For example, this command removes all the files in C:\test:

Example


# Using PowerShell commnads to delete all file
Remove-Item -Path "C:\test\*.*"
 

Copy and Try it


Here also you can use -Force command to delete files force fully

Example


# Using PowerShell commnads to delete all file force fully
Remove-Item -Path "C:\test\*.*" -Force
 

Copy and Try it


Here also ypou can use -Force command to delete files force fully

Example


# Using PowerShell commnads to delete all file and folders
Remove-Item -Path "C:\test\*.*" -recurse

Copy and Try it

Example


Remove-Item -Recurse -Force some_dir

Copy and Try it

does indeed work as advertised here.

Example


rm -r -fo some_dir

Copy and Try it

there are shorthand aliases that work too.

As far as I understood it, the -Recurse parameter just doesn't work correctly when you try deleting a filtered set of files recursively. For deleting a single dir and everything below it seems to work fine.

Delete-SharePoint-Files-With-PowerShell