<# .SYNOPSIS This script displays the count of items in a hash table. .DESCRIPTION This script creates a hash table then prints out the number of items in the table. .NOTES File Name : Author : Thomas Lee - tfl@psp.co.uk Requires : PowerShell Version 2.0 Tested : PowerShell Version 5 .LINK This script posted to: http://pshscripts.blogspot.co.uk/2008/07/count-hashtableps1.html .EXAMPLE 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 $myht
This blog contains PowerShell scripts, more PowerShell scripts and still more PowerShell scripts. Occasionally you may see some organisational posts.
Showing posts with label count. Show all posts
Showing posts with label count. Show all posts
Tuesday, 15 July 2008
Count-Hashtable.ps1
Labels:
add,
count,
powershell,
scripts,
system.collections.hashtable
Subscribe to:
Posts (Atom)