Archive for the ‘Search and Delete Files (Extension Search)’ Category

Search and Delete Files (Extension Search)

November 11, 2014 Leave a comment

I wrote this script to find file’s with a specific extension and take action such as delete.

$_SearchExtension=Read-Host "search file (extension *.trn,*.BAK etc ):" $_SourcePath=Read-Host "Folder location:" $_Action=Read-Host "Action (0=Print,1=Print and Delete):" $_fileex=$_SearchExtension Write-Host "" $_Fpath=$_SourcePath $_files = get-childitem -Path $_Fpath -filter $_fileex

-Recurse -ErrorAction SilentlyContinue

-Verbose |? {$_.PsIscontainer -eq $false } foreach($_f in $_files) { if($_Action -eq 0) { Write-Host "FileName : " $_f.fullname} elseif($_Action -eq 1) { Write-Host "FileName : " $_f.fullname remove-item $_f.fullname } }