Solved

Find and Delete Specific Files with Powershell

Posted on 2011-09-14
6
741 Views
Last Modified: 2012-05-12
Greetings everyone
I am trying to figure a way to use Powershell to scan multiple directories to search and remove a specific file type. "._NH Speedway wide.mov" The issue I am having is that the file information following the underscore changes based on the parent file name. These files are created on a FinalCut Pro NLE system running MAC OS 10.5 and copied to a Windows Server 2008 R2. I have no issues with finding the standard ".mov" files with a scritp but I have not been able to list these type of files. Any ideas would be greatly appreciated. Here is the script that works for normal file extensions but not the ones I need to find:

# PowerShell script to list the ._xxx.mov Files on the server
$Dir = get-childitem \\xxx-xxxx\Media_Exchange -recurse
# $Dir |get-member
($List = $Dir | where {$_.extension -eq "._*.mov"}).count
$List | format-table name

0
Comment
Question by:EICBOB
  • 3
  • 3
6 Comments
 
LVL 16

Accepted Solution

by:
Dale Harris earned 500 total points
ID: 36539233
What if you changed it to:

# PowerShell script to list the ._xxx.mov Files on the server
($List = get-childitem \\IP\Media_Exchange -recurse | ?{$_.name.contains("._")}).count
$List | ft name


Does that find the files you're looking for?

HTH,

Dale Harris
0
 

Author Comment

by:EICBOB
ID: 36543236
Hi Dale
Your edit does indeed return a list of files with other extensions, it does not return the list of .mov files.
Here is the script now:

# PowerShell script to list the ._xxx.mov Files on the SQL server
# $Dir = get-childitem \\xxx-xxxx\Media_Exchange -recurse
($List = get-childitem \\wcsh-sql01\Media_Exchange -recurse | ?{$_.name.contains("._")}).count
$List | ft name

Here is a snippet of the output:

82

Name                                                                                                                                
----                                                                                                                                
._501                                                                                                                                
._motionVFX_Free_After_Effects_Project_001.aep                                                                                      
._Handwriting - Dakota                                                                                                              
._.DS_Store                                                                                                                          
._DropZone01.png                                                                                                                    
._DropZone02.png                                                                                                                    
._DropZone03.png                                                                                                              
._How to Install Tapio's FxPack.rtfd                                                                                                
._Light Sweep.qtz                                                                                                                    
._Light_Sweep.png                                                                                                                    
._Numbers 1.2.qtz                                                                                                                    
._Numbers.png                                                                                                                        
._Tapios FXPack.png                                                                                                                  
._FxPackComparison.jpg                                                                                                              
._Noise-Industries.png                                                                                                              
._TXT.rtf                                                                                                                            

0
 
LVL 16

Assisted Solution

by:Dale Harris
Dale Harris earned 500 total points
ID: 36544681
Try this:

($List = get-childitem \\wcsh-sql01\Media_Exchange -recurse -filter "._*.mov" -force).count
$List | ft fullname

The addition of the -force parameter will show you any hidden files or protected system files that are possibly causing the issue with not showing .mov files.

The -filter parameter is our search filter, anything with ._ in the beginning and ending with .mov will be included

I've changed the ft to Fullname so it will show you the path and extension.

HTH,

Dale Harris
0
Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

 

Author Comment

by:EICBOB
ID: 36545711
Hi Dale
Awesome! that worked, now one more minor thing, now that I have the files I want to delete them!

Thanks!

Bob
0
 
LVL 16

Assisted Solution

by:Dale Harris
Dale Harris earned 500 total points
ID: 36545819
You can add a pipe and remove-item cmdlet

($List = get-childitem \\wcsh-sql01\Media_Exchange -recurse -filter "._*.mov" -force).count
$List | ft fullname
$List | Remove-Item

Tested and works even throughout multiple directories without actually removing a directory.

Good luck!

Dale
0
 

Author Closing Comment

by:EICBOB
ID: 36545844
Thank you Dale you have saved me from taking a large heavy object to my keyboard!
0

Featured Post

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

This is a PowerShell web interface I use to manage some task as a network administrator. Clicking an action button on the left frame will display a form in the middle frame to input some data in textboxes, process this data in PowerShell and display…
This article will help you understand what HashTables are and how to use them in PowerShell.
The view will learn how to download and install SIMTOOLS and FORMLIST into Excel, how to use SIMTOOLS to generate a Monte Carlo simulation of 30 sales calls, and how to calculate the conditional probability based on the results of the Monte Carlo …
The viewer will learn how to create two correlated normally distributed random variables in Excel, use a normal distribution to simulate the return on different levels of investment in each of the two funds over a period of ten years, and, create a …

746 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now