Hi,
I have a collection of PSObjects which contains several values. My goal is to produce a list of unique AppToken objects but the kicker is if a duplicate object exists, I need to keep the newest one (which can be determined by dtCreatedDate)
Here's what I have tried (Unsuccessfully)
$tokenTable = $tokenTable|sort-object -property @{Expression="dtCreatedDate";Descending=$true} $tokenTable = $tokenTable|sort-object -property @{Expression="AppToken";Descending=$true} |get-unique -asstring
I can get the commands to work individually, but not together.
I also tried a one liner:
$tokenTable = $tokenTable|sort-object -property@{Expression="AppToken";Descending=$true},@{Expression="dtCreatedDate";Descending=$false}|get-unique -asstring
Here's what the object looks like:
TypeName: Selected.System.Management.Automation.PSCustomObject
Name MemberType Definition
---- ---------- ----------
Equals Method bool Equals(System.Object obj)
GetHashCode Method int GetHashCode()
GetType Method type GetType()
ToString Method string ToString()
ApplicationDisplayName NoteProperty System.String ApplicationDisplayName=website
AppToken NoteProperty System.String AppToken=/dty
DatabaseName NoteProperty System.String DatabaseName=DB1
DBServer NoteProperty System.String DBServer=DBSQL1
dtCreatedDate NoteProperty System.DateTime dtCreatedDate=10/03/11 6:24:13 AM
isCustom NoteProperty System.Boolean isCustom=False
IsEnabled NoteProperty System.Boolean IsEnabled=False