I plagiarized this code and updated it a little bit. The original code is here: mp3-tag
Function Get-MP3MetaData {
[CmdletBinding()]
[Alias()]
[OutputType([Psobject])]
Param
(
[Parameter(Mandatory = $true, ValueFromPipeline = $true)]
[String] $Directory
)
Begin {
$shell = New-Object -ComObject "Shell.Application"
$PropertArray = 0, 1, 2, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 27, 28, 36, 220, 223
}
Process {
Foreach ($Dir in $Directory) {
$ObjDir = $shell.NameSpace($Dir)
$SearchDir = $Dir + "\*" # when Get-ChildItem uses -Include the Path must end with *
Get-ChildItem $SearchDir -File -Include *.mp3,*.mp4 |
ForEach-Object{
$ObjFile = $ObjDir.parsename($_.Name)
$MetaData = [ordered]@{}
Foreach ($item in $PropertArray) {
If ($ObjDir.GetDetailsOf($ObjFile, $item)) { #To avoid empty values
$MetaData[$($ObjDir.GetDetailsOf($MP3, $item))] = $ObjDir.GetDetailsOf($ObjFile, $item)
}
}
$MetaData['Directory'] = $Dir
$MetaData['Fullname'] = (Join-Path $Dir $_.Name -Resolve)
$MetaData['Extension'] = $_.Extension
[PSCustomObject]$MetaData
}
}
}
End {
}
}
# Example of how to use the function:
#ForEach($item in ("D:\Powershell\Tutorials\4_DSC" |Get-MP3MetaData)){
# $NewName = [regex]::Replace($(($item.Title).Split(":")[1].Trim() + $item.extension),"[*(/)\\&#]",{''})
# $Oldname = $item.Fullname
# Rename-Item -LiteralPath $item.Fullname -NewName $NewName -Force
#}