Solved

Find and Delete Specific Files with Powershell

Posted on 2011-09-14
6
748 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:Bob Conklin
  • 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:Bob Conklin
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
Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

 

Author Comment

by:Bob Conklin
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:Bob Conklin
ID: 36545844
Thank you Dale you have saved me from taking a large heavy object to my keyboard!
0

Featured Post

U.S. Department of Agriculture and Acronis Access

With the new era of mobile computing, smartphones and tablets, wireless communications and cloud services, the USDA sought to take advantage of a mobilized workforce and the blurring lines between personal and corporate computing resources.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

How to sign a powershell script so you can prevent tampering, and only allow users to run authorised Powershell scripts
Synchronize a new Active Directory domain with an existing Office 365 tenant
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 use a discrete random variable to simulate the return on an investment over a period of years, create a Monte Carlo simulation using the discrete random variable, and create a graph to represent the possible returns over…

856 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