I have the following function defined in a ps1 file, using the DLL from the latest taglib release. I downloaded the nuget package and ran expand-archive on it and copied the DLL to the correct place.
[System.Reflection.Assembly]::LoadFrom((Resolve-Path ($PSScriptRoot + "\TagLibSharp.dll")))
function Get-Image {
[CmdletBinding()]
param (
[Parameter(ValueFromPipelineByPropertyName)] $Name
)
process {
$fullPath = (Resolve-Path $Name).Path
$image = [taglib.file]::create($fullpath)
return $image
}
}
function Get-ImmediatePhotos {
Get-ChildItem | Where-Object {$_.Extension -eq ".jpg" -or $_.Extension -eq ".png"} | Get-Image
}
When I run this command to extract the years from the EXIF data in photos in a given directory I get a table like this:
> $years = Get-ImmediatePhotos | select-object {$_.Tag.DateTime.Year}
> $years
$_.Tag.DateTime.Year
--------------------
2020
2020
2020
2020
2020
2020
2020
2020
2020
2020
2021
2021
2021
2021
If I then try to extract unique years with sort-object I only get one year!
> $years | sort-object -unique
$_.Tag.DateTime.Year
--------------------
2020
If I try to group years with group-object I get this error:
$years | group-object
Group-Object: Cannot compare "@{$_.Tag.DateTime.Year=2020}" to
"@{$_.Tag.DateTime.Year=2020}" because the objects are not the same type or the object
"@{$_.Tag.DateTime.Year=2020}" does not implement "IComparable".
This seems to be telling me that the type of values in the column are some sort of anonymous thing which can't be compared.
How do I use the results of select as values, such as strings? My end goal is to automatically sort and categorize photos into directories in /year/month format.