Category Archives: Files

Sorting mp3 files based on Album ID3 Tags in Powershell

I had a large number of mp3 files that were all in a single folder, however the album ID3 tag were all correct.  I used powershell and taglib-sharp.dll to read the album ID3 tag, create a folder and move the mp3 into that folder.
Taglib-sharp.dll can be found here (new window).
The powershell code at pastebin here (new window).
You will need to edit the variables:
#folderToSearch is the folder that has the files
#taglibLocation is the location of the taglib-sharp.dll
#fileExtension is the file extension of the files with the ID3 tags (eg: mp3, wma, etc)

It can also be used with WMA files, and possibly any files that contain album ID3 tags, and with a little modification, any ID3 tag can be used.

Delete Files Containing a Specific String Using Powershell

I had a number of files, and wanted to delete the files that contained a specific string.  Using Powershell, this can be completed using the following (one line):

get-childitem *.txt | select-string “%STRING_TO_DELETE%” | group path | select name | foreach-object {remove-item $_.name}

Where %STRING_TO_DELETE% is the string that will determine if the file is deleted. EG (one line):


get-childitem *.txt | select-string “SUCCESS” | group path | select name | foreach-object {remove-item $_.name}
 
This will delete any .TXT files in the current directory that contain the string SUCCESS
 
Specifically this was used to remove emails from the mail queue of an Exchange 2003 server that was spamming after a user account was compromised.  I noticed the spam all contained the string “I have urgent feasible plan aligned with our mutual economical interests”.  Using Powershell, I navigated to the mail queue directory, and used the following command:
 

get-childitem *.eml | select-string “I have urgent feasible plan aligned with our mutual economical interests” | group path | select name | foreach-object {remove-item $_.name}

This deleted all the .eml files with the spam string.