Get Unique Objects from Array of Objects by Property in PowerShell

In real-time application requirements, we will work with a custom PowerShell object array (complex object) instead of a simple string or integer array. The Unique switched parameter can also be used to find distinct objects by a property in a custom object array.

# Initialize the array
$Array = @()
 
$Array += [PSCustomObject]@{ Name = "User1"; }
$Array += [PSCustomObject]@{ Name = "User2"; }
$Array += [PSCustomObject]@{ Name = "User2"; }
$Array += [PSCustomObject]@{ Name = "User3"; }
 
$ResultArray = $Array | Select-Object -Unique -Property Name
  
$ResultArray # Result array with unique Name values
  
Name
----
User1
User2
User3

As already explained, the Unique parameter with Select-Object cmdlet finds unique values with case-sensitive string comparison. If you work with a string property and want to perform a case-insensitive string comparison to find distinct objects, then we need to use the Unique parameter with Sort-Object cmdlet to perform a case-insensitive check.

# Initialize the array
$Array = @()
 
$Array += [PSCustomObject]@{ Name = "User1"; }
$Array += [PSCustomObject]@{ Name = "user2"; }
$Array += [PSCustomObject]@{ Name = "User2"; }
$Array += [PSCustomObject]@{ Name = "User3"; }
 
# Find unique objects by case-sensitive comparison.
$Array | Select-Object -Unique -Property Name
  
Name
----
User1
user2
User2
User3 
  
# Find unique objects by case-insensitive comparison.
$Array | Sort-Object -Unique -Property Name 
  
Name
----
User1
User2
User3
PowerShell
Distinct
Unique

Comments (4)

KennethDap

9/6/2023 1:57:08 AM
Looking for an exciting escape into the world of adult comics? Look no further than Mult34.com! Our website is your ultimate destination for a diverse range of erotic comics that cater to various tastes and preferences. With just one click, you'll unlock a treasure trove of sensually captivating stories and visuals that will leave you craving for more. [url=https://mult34.com/category/the-loud-house/]the loud house fanfiction[/url] - That's the key to unlock a realm of passionate encounters, thrilling narratives, and artistic expression like no other. Our collection features a wide spectrum of adult content, from steamy romances to tantalizing fantasies. You'll find comics that explore every aspect of desire and pleasure, all tastefully crafted by talented artists who excel in the art of erotic storytelling. Whether you're a long-time enthusiast or a curious newcomer, Mult34.com provides a safe and discreet platform to explore your fantasies and indulge in your deepest desir

Vikcomres

9/5/2023 2:24:43 PM
Unleash your inner desires and step into a world of seduction and artistic expression at Mult34.com. We're not just a website; we're a portal to a realm of adult comics that will ignite your passions and captivate your senses. [url=https://mult34.com/]porn comics[/url] – that's the key that opens the door to a diverse and tantalizing collection of adult comics. Whether you crave sizzling romances that set your heart racing or crave immersive fantasies that transport you to another world, Mult34.com has it all. Our curated selection is a testament to the power of erotic storytelling, where skilled artists weave intricate narratives through stunning visuals. Privacy and discretion are our utmost priorities. We provide a safe, judgment-free space for adults to explore their deepest fantasies. Our user-friendly interface ensures that you can seamlessly navigate our vast library, discovering new comics that resonate with your desires. Join our vibrant community of erotica en

Zasvenufep

9/3/2023 4:00:39 AM
Explore a world of adult storytelling tailored for the sophisticated tastes of gentlemen aged 18 and above at hentailoop.com. Our platform, [url=https://hentailoop.com/tag/doujinshi/]hentai doujinshi[/url] , invites you to embark on immersive journeys that blend captivating narratives, stunning visuals, and a diverse range of characters. At hentailoop.com, we understand the art of crafting stories that resonate with our readers. With a curated collection that spans genres, from steamy encounters to thought-provoking dramas, our [url=https://hentailoop.com/releases/2023/]hentai doujin[/url] promise to enthrall and entertain. Whether you're captivated by anime personas or drawn to the allure of classic comic legends, we have something for everyone. Beyond the pages, hentailoop.com cultivates a vibrant community where discussions thrive, interpretations unfold, and friendships are forged. Engage with fellow enthusiasts who share your passion for narratives that extend beyond in

Avromanfep

9/2/2023 1:13:27 PM
Get ready to elevate your entertainment experience with a touch of sophistication and a dash of allure – welcome to hentailoop.com, the epicenter of [url=https://hentailoop.com/manga/hypnosis-is-awesome/]hypno hentai[/url] . Crafted exclusively for the refined tastes of adults aged 18 and above, our website is a haven of creativity, imagination, and visual delight. [url=https://hentailoop.com/manga/azur-lane-crimson-axis-aphrodisiac-therapy/read/p/7/]azur lane hentai[/url] is more than a collection of pages; it's a sanctuary where art and storytelling converge to whisk you away on unforgettable journeys. Immerse yourself in a world where each comic is a masterpiece, where characters breathe with life and emotions run deep. Our curated selection offers a plethora of genres, from steamy encounters to thought-provoking dramas, all designed to captivate your senses. But hentailoop.com is more than a website; it's a gathering place for kindred spirits, a community where enthusias

Leave a Comment

All fields are required. Your email address will not be published.