Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Find and Delete Specific Files with Powershell

Posted on 2011-09-14
6
Medium Priority
?
775 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3
6 Comments
 
LVL 16

Accepted Solution

by:
Dale Harris earned 2000 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 2000 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
Are You Ready for GDPR?

With the GDPR deadline set for May 25, 2018, many organizations are ill-prepared due to uncertainty about the criteria for compliance. According to a recent WatchGuard survey, a staggering 37% of respondents don't even know if their organization needs to comply with GDPR. Do you?

 

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 2000 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

Protect Your Retail Business and Reputation

Wi-Fi access doesn't just impact your business & customer experience, it can also affect your security.  Join us for an informative webinar to learn more about the top threats and trends impacting retail today, and the key solutions to protecting retail networks and reputations.

Question has a verified solution.

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

A brief introduction to what I consider to be the best editor for PowerShell.
My attempt to use PowerShell and other great resources found online to simplify the deployment of Office 365 ProPlus client components to any workstation that needs it, regardless of existing Office components that may be needing attention.
The viewer will learn how to simulate a series of sales calls dependent on a single skill level and learn how to simulate a series of sales calls dependent on two skill levels. Simulating Independent Sales Calls: Enter .75 into cell C2 – “skill leve…
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 …

660 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