PowerShell – Remove all files from a folder

  Powershell

This script will delte everyting in the “Script” folder, sub-folder, and the “-recurse” option will prevent the prompting of confirmation. The “-exclude” option alllows you to exclude files and folders.

Remove-Item c:\scripts\* -recurse -exclude *.wav

Alternative;

$Path = '\\servername\folder'
Get-ChildItem -Path $Path -Recurse | Remove-Item -Force -Recurse

More on the Remove-Item Powershell cmdlet can be found here:

Powershell 1.0
http://technet.microsoft.com/en-us/library/ee176938.aspx

Powershell 4.0
http://technet.microsoft.com/en-us/library/hh849765.aspx

Leave a comment