Posts Tagged ‘BinarySearch’
Custom IComparers in PowerShell (and Add-Type for v1)
Someone asked the question in #PowerShell (on irc.Freenode.net):
How do I find an item (in an array) based on one of it’s properties?
Actually, the question was rather more complicated than that. They were importing a bunch of users from a csv file, and wanted to sort them and search them based on a specific column. There are many ways to skin this cat. Imagine that you have a CSV file, and have imported it, like so:
Set-Content users.csv @"
LastName, FirstName, UserName, Url
Bennett, Joel, Jaykul, http://HuddledMasses.org
Rottenberg, Hal, HalR9000, http://halr9000.com
Hicks, Jeffrey, SapienScripter, http://blog.sapien.com/
"@
$users = Import-Csv .\users.csv
Now, imagine that the CSV file has thousands of users in it, and that you need to not only sort the data by first name or last name on demand, but you also need to pull users from the list (by name) on demand.
These are trivial tasks in PowerShell: Read the rest of this entry »