Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function Get-MetaData
- {
- PARAM
- (
- [PARAMETER(Mandatory=$true)]
- [string]$path = ""
- , [PARAMETER( Mandatory=$true,
- HelpMessage="extension IE. .mp3, .txt or .mov")]
- [string]$type = ""#'mp3'
- , [switch]$recurse
- )
- if ($recurse)
- {
- $LPath = Get-ChildItem -Path $path -Directory -Recurse
- } else {$LPath = $path}
- $DirectoryCount = 1
- $RetrievedMetadata = $true
- $OutputList = New-Object 'System.Collections.generic.List[psobject]'
- Foreach ($pa in $LPath)
- {
- $shell = New-Object -ComObject shell.application
- if ($recurse)
- {
- $objshell = $shell.NameSpace($pa.FullName)
- } else {$objshell = $shell.NameSpace($pa)}
- #Build data list
- $count = 0
- #Filter on filetype
- $filter = $objshell.items() | where {$_.path -match $type}
- foreach ($file in $filter)
- {
- if ($RetrievedMetadata)
- {
- # Build metanumbers
- Write-Verbose "Building MetaIndex for filetype $type"
- $Metanumbers = New-Object -TypeName 'System.Collections.Generic.List[int]'
- for ($a = 0 ; $a -le 400;$a++)
- {
- if ($objshell.GetDetailsOf($file,$a))
- {
- $Metanumbers.Add([int]$a)
- }
- }
- $RetrievedMetadata = $false
- Write-Verbose "$($Metanumbers.Count) entries in MetaIndex for filetype $type"
- }
- $count++
- $CurrentDirectory = Get-ChildItem -Path $file.path
- try{
- Write-Progress -Activity " Getting metadata from $DirectoryCount/$($LPath.count) $($CurrentDirectory[0].DirectoryName)" -Status "Working on $count/$($filter.count) - $($file.Name)" -PercentComplete (($count / $filter.count) * 100) -ErrorAction stop
- }catch{}
- #Build Hashtable for each file
- $Hash = [ordered]@{}
- foreach ($nr in $Metanumbers)
- {
- $PropertyName = $($objshell.GetDetailsOf($objshell.Items, $nr))
- $PropertyValue = $($objshell.GetDetailsOf($File, $nr))
- $Hash[$PropertyName] = $PropertyValue
- $Hash.Remove("")
- }
- $FileMetaData = New-Object -TypeName PSobject -Property $hash
- $OutputList.Add($FileMetaData)
- $hash = $null
- }
- $DirectoryCount++
- }
- Write-Verbose "MetaData for $($OutputList.count) files found"
- return $OutputList
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement