Friday, 4 July 2008


    Demonstrates a .NET Queue object
    This script creates a queue, adds some items to it, and 
	displays the queue. Finally, the clear method is called and results
    File Name  : show-queue.ps1
	Author     : Thomas Lee -
	Requires   : PowerShell V2 CTP3
	Tags       : system.collections.queue, enque, clear, powershell, scripts
    PS c:\foo> .\show-queue.ps1
	$myq object
    3 entries in the queue as follows
    entry 0:  Hello
    entry 1:  World
    entry 2:  !
	$myq object after the clear:
    0 entries in the queue as follows:
    queue is empty

#  Start of script

# Create new queue object and add three objects to it
$myq = new-object system.collections.Queue
# Display the properties and values of the Queue
"`$myq object"
"`{0} entries in the queue as follows" -f $myq.Count
$myq | % {"entry {0}:  {1}" -f $i++,$_ }

# Now clear the queue

#show results
"";"`$myq object after the clear:"
"`{0} entries in the queue as follows:" -f $myq.Count
if ($myque.count -gt 0)
  {$myq | % {"entry {0}:  {1}" -f $i++,$_ }}
  {"queue is empty"}
# End of Script

No comments: