PowerWF News, Tutorials, and more...

Get the latest tips and tricks directly from the PowerWF development team. Find out about new releases and upcoming features.


Seamless Automation

From the Desktop to the Data Center

The PowerWF family of products are easy enough for desktop and departmental automation, yet powerful and scalable enough for the Data Center. PowerWF compliments Opalis and other RBA solutions, lets you leverage your workforce and preserves your investment as your automation needs grow.


Special - 20% Discount


In conjunction with our recently announced Silver Award from Windows IT Magazine we would like to offer our customers an opportunity to save 20% off any Devfarm product purchase through the end of the year. This includes all PowerWF products as well as Devfarm's new PowerVI product!

PowerVI

vSphere Automation fueled by PowerShell


Designed for the VMware Administrator, PowerVI eases the automation of vSphere infrastructures. PowerVI includes over 100 PowerShell automation scripts that simplify everyday VMware administration tasks and PowerVI makes it easy to author new scripts.
December 5, 2011

Get HashTable Max Value

@XCUD had another interesting chat the other day related to Hash Tables.  He was going to blog about it, but he’s busy working on some very cool features for the next version of PowerWF.

Anyway, the question was, what is the easiest way to find the max value in a Hash table.  We decided it was easiest to sort the hash table and then return the first value.  Here is an example (albeit  a silly one)

# Easiest way to get the max value from a hash table #
function get-HashMaxValue($hashTable)
{
    return $hashTable.GetEnumerator() | sort value -Descending | select -First 1 
}

# Let's try it out
$myHash = @{}

# Populate a hash table
get-Process c* | foreach-object -Process {$myHash.add($_.Name + $_.Id, $_.CPU)}

# Output the results
$myHash

# And call our function...
write-Output "`n`nAnd the Winner is..."
get-HashMaxValue $myHash


blog comments powered by Disqus