first, always good to find your own forum posts when googling for how to do stuff
that was the second part of a bigger question i was answering today. basically i’m pulling an array of $sources with a ‘path’ column whose values look like ‘share/folder/subfolder/’ (yes, with those slash directions) from one location, and and array of $allstats from a mysql query, which has a “sourcefilename” column with a similar path as $sources. i just want a count of how many times each $source.path appears in $allstats. i just have to do a little manipulation with the slash directions.
i came up with three ways to do this query. version 1 was even before the previous paragraph, i was looping through $sources and re-querying the mysql database repeatedly for each $source.path. pretty slow. then i figured it’d be faster to pull the whole mysql query into powershell once, and then loop through that PS array looking for each $source. so that array is $allstats.
version 2, i foreach through each $source, and nest another foreach going through each line in $allstats to see if it matches, then increment a counter if they do.
version 3, i do ($allstats | where-object -blah blah).count.
(hoping this gist link works)
v3 looks like a cleaner way to do the same thing as v2, but but v3 takes about 30% longer to run, according to measure-command. which made me wonder why, and made me wonder if there’s a way to do it that’s 30% faster than v2.