Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 783
  • Last Modified:

Find and Delete Specific Files with Powershell

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
Bob Conklin
Asked:
Bob Conklin
  • 3
  • 3
3 Solutions
 
Dale HarrisCommented:
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
 
Bob ConklinConfiguration/TEST TechnicianAuthor Commented:
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
 
Dale HarrisCommented:
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
NEW Veeam Backup for Microsoft Office 365 1.5

With Office 365, it’s your data and your responsibility to protect it. NEW Veeam Backup for Microsoft Office 365 eliminates the risk of losing access to your Office 365 data.

 
Bob ConklinConfiguration/TEST TechnicianAuthor Commented:
Hi Dale
Awesome! that worked, now one more minor thing, now that I have the files I want to delete them!

Thanks!

Bob
0
 
Dale HarrisCommented:
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
 
Bob ConklinConfiguration/TEST TechnicianAuthor Commented:
Thank you Dale you have saved me from taking a large heavy object to my keyboard!
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 3
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now