Tuesday, 15 July 2008


    This script displays the count of items 
    in a hash table.
    This script creates a hash table then 
    prints out the number of items in the table.
    File Name  : 
    Author     : Thomas Lee - tfl@psp.co.uk
    Requires   : PowerShell Version 2.0
    Tested     : PowerShell Version 5
    This script posted to:
    PS c:\foo > .\count-hashtable.ps1
    There are 4 elements in $myht as follows:

    Name                   Value                                                                              
    ----                   -----                                                                             
    four                   fox
    one                    The    
    three                  brown  
    two                    quick

# Create hashtable and add four elements
$myht = new-object system.collections.hashtable
$myht.Add( "one", "The" )
$myht.Add( "two", "quick" )
# or doing it the PowerShell way
$myht += @{"three" = "brown" }
$myht += @{"four" = "fox"}

# Display the Hashtable
"There are {0} elements in `$myht as follows:" -f $myht.count

No comments: