Showing posts with label clear. Show all posts
Showing posts with label clear. Show all posts

Wednesday, 23 July 2008

Clear-Stack.ps1

<#
.SYNOPSIS
    Sample of clearing a stack using PowerShell    
.DESCRIPTION
    This script creates a script and shows the impact of clearing the stack
.NOTES
    File Name  : clear-stack.ps1
    Author     : Thomas Lee - tfl@psp.co.uk
    Requires   : PowerShell V2
.LINK
    http://pshscripts.blogspot.com/2008/07/clear-stackps1.html
.EXAMPLE
    PSH [C:\foo]: .\clear-stack.ps1
    Initially,
       Count    : 5
       Values:
    jumped
    fox
    brown
    quick
    The
    After Clear,
       Count    : 0
       Values:

#>

##
# Start of script
##

# Create stack
$stack = New-Object system.collections.stack
$Stack.Push( 'The' );
$Stack.Push( 'quick' );
$Stack.Push( 'brown' );
$Stack.Push( 'fox' );
$Stack.Push( 'jumped' );
 
# Display the count and values of the Stack
'Initially,'
'   Count    : {0}' -f $Stack.Count
'   Values:'
$Stack
 
# Clear the Stack
$Stack.Clear()

# Display the count and values of the Stack
'After Clear,'
'   Count    : {0}' -f $Stack.Count
'   Values:'
$Stack

Sunday, 13 July 2008

Clear-Hashtable.ps1

<#
.SYNOPSIS
    Demonstrates Hashtable's Clear Method 
.DESCRIPTION
    This script creates and populates a hash table then demonstrates
    use of the .clear method.
.NOTES
    File Name  : Clear-HashTable.ps1
    Author     : Thomas Lee - tfl@psp.co.uk
    Requires   : PowerShell V2 CTP3
.LINK
    http://www.pshscripts.blogspot.com
.EXAMPLE
    PS C:\foo> .\ClearHashTable.ps1
    Initially,
       Count    : 5
       Values:

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

    After Clear,
       Count    : 0
       Values:
#>

##
#  Start of Script
##

# Create and populate a hash table
$MyHashTable= @{}
$MyHashTable.Add( "one",   "The"     )
$MyHashTable.Add( "two",   "quick"   )
$MyHashTable.Add( "three", "brown" )

# Add using the PowerShell way: :-)
$MyHashTable += @{"four"="fox"   }
$myHashTable += @{"five"="jumped"}

# Display the count and values of the Hashtable
"Initially," 
"   Count    : {0}" -f $MyHashTable.Count
"   Values:"
$MyHashTable

# Clear the Hashtable.
$MyHashTable.Clear()
""

# Display the count and values of the Hashtable
"After Clear," 
"   Count    : {0}" -f $MyHashTable.Count 
"   Values:"
$MyHashtable
# End of script

Friday, 4 July 2008

Show-Queue.ps1


<#
.SYNOPSIS
    Demonstrates a .NET Queue object
.DESCRIPTION
    This script creates a queue, adds some items to it, and 
	displays the queue. Finally, the clear method is called and results
	displayed.
.NOTES
    File Name  : show-queue.ps1
	Author     : Thomas Lee - tfl@psp.co.uk
	Requires   : PowerShell V2 CTP3
	Tags       : system.collections.queue, enque, clear, powershell, scripts
.LINK
    http://www.pshscripts.blogspot.com
.EXAMPLE
    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
$myq.Enqueue("Hello")
$myq.Enqueue("World")
$myq.Enqueue("!")
 
# Display the properties and values of the Queue
"`$myq object"
$i=0
"`{0} entries in the queue as follows" -f $myq.Count
$myq | % {"entry {0}:  {1}" -f $i++,$_ }

# Now clear the queue
$myq.clear()

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