Solved

Find and Delete Specific Files with Powershell

Posted on 2011-09-14
6
745 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
Ransomware-A Revenue Bonanza for Service Providers

Ransomware – malware that gets on your customers’ computers, encrypts their data, and extorts a hefty ransom for the decryption keys – is a surging new threat.  The purpose of this eBook is to educate the reader about ransomware attacks.

 

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

I thought I'd write this up for anyone who has a request to create an anonymous whistle-blower-type submission form created using SharePoint 2010 (this would probably work the same for 2013). It's not 100% fool-proof but it's as close as you can get…
"Migrate" an SMTP relay receive connector to a new server using info from an old server.
Viewers will learn the different options available in the Backstage view in Excel 2013.
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 …

809 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