PS: Get-FileMetaInformation
This script returns either all available meta information of a given file. Or it returns the value of a specific meta entry of the given file.
Example:
to retrieve alle available meta elements of the file "MyFavouritePicture.jpg" use the following command:
Get-FileMetaInformation -FileName "MyFavouritePicture.jpg"
The script will return something like this:
or this for a "normal" file:
Version History:
- 1.0.0 - Initial release
Download the script:
>> Version 1.0.0 (current)
(MD5: 0c5d26e4c17db1c82714a77237bea9a6)
(SHA1: 8c3f981abfd253d2de8e3a03a5f3789d5638d317)
Script code:
##------------------------------------------------------------------------------------------------
##
## Get-FileMetaInformation.ps1
##
## Version 1.0.0
##
##
## Copyright (c) 2016 Martin Mueller - www.sh-soft.com
##
## Permission is hereby granted, free of charge, to any person obtaining a copy of this software
## and associated documentation files (the "Software"), to deal in the Software without
## restriction, including without limitation the rights to use, copy, modify, merge, publish,
## distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the
## Software is furnished to do so, subject to the following conditions:
##
## The above copyright notice and this permission notice shall be included in all copies or
## substantial portions of the Software.
##
## THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
## BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
## NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
## DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
## FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
## (The MIT License (MIT))
##
##------------------------------------------------------------------------------------------------
<#
.SYNOPSIS
This script shows available meta information of a single given file or returns the value of a meta value.
.DESCRIPTION
This script shows available meta information of a single given file or returns the value of a meta value.
.PARAMETER FileName
[required] File name to analyze
.PARAMETER ReturnFieldID
if given and correct it returns only the Content of a metadata property id
.EXAMPLE
Get an overview of all Meta properties of a given file
.\Get-FileMetaInformation.ps1 -FileName YourFileName.jpg
.EXAMPLE
Get the value of field 12 (Date Taken) from a given file
.\Get-FileMetaInformation.ps1 -FileName YourFileName.jpg -ReturnFieldID 12
#>
#------------------------------------------------------------------------------------------------
# Parameter block
#------------------------------------------------------------------------------------------------
param (
[Parameter(Mandatory=$true,HelpMessage='File Name to be used to retreive meta information',Position=0)]
[string]$FileName,
[Parameter(HelpMessage='Field ID in the Meta Information to be returned',valueFromPipeline=$true)]
[int]$ReturnFieldID
)
BEGIN {
}
##------------------------------------------------------------------------------------------------
## main block...
##------------------------------------------------------------------------------------------------
PROCESS {
if (-not ($FileName.Contains("`\"))) {
$FileName = Join-Path -Path (Split-Path -Parent -Path $MyInvocation.MyCommand.Definition) -ChildPath $FileName
}
$FileMetaData = New-Object PSOBJECT
$objShell = New-Object -ComObject Shell.Application
$objFolder = $objShell.namespace((Split-Path -Path $FileName -Parent))
$FileData = $objFolder.Items().Item((Split-Path -Path $FileName -Leaf))
if (-not $ReturnFieldID -or ($ReturnFieldID -lt 0 -or $ReturnFieldID -gt 999)) {
for ($CurrentFieldID = 0; $CurrentFieldID -le 999; $CurrentFieldID++) {
if($objFolder.getDetailsOf($FileData, $CurrentFieldID)) {
[string]$StringCurrentID = $CurrentFieldID
while ($StringCurrentID.Length -lt 3) {
$StringCurrentID = " "+$StringCurrentID
}
$MetaEntry += @{"[ID: $StringCurrentID]`t$($objFolder.getDetailsOf($objFolder.items, $CurrentFieldID))" = $objFolder.getDetailsOf($FileData, $CurrentFieldID) }
$FileMetaData | Add-Member $MetaEntry
$MetaEntry.clear()
}
}
return $FileMetaData
}
else {
if (($objFolder.getDetailsOf($FileData, $ReturnFieldID))) {
return ($objFolder.getDetailsOf($FileData, $ReturnFieldID))
}
else {
return "ERR: FieldID not Found or Empty"
}
}
}
END {
}