Clear-Stack


posted by ps3
07-24-2009

Downloads: 291
File size: 1.1kB
Views: 697

Embed
Clear-Stack
  1. <# 
  2. .SYNOPSIS 
  3.     Sample of clearing a stack using PowerShell     
  4. .DESCRIPTION 
  5.     This script creates a script and shows the impact of clearing the stack 
  6. .NOTES 
  7.     File Name  : clear-stack.ps1 
  8.     Author     : Thomas Lee - tfl@psp.co.uk 
  9.     Requires   : PowerShell V2 CTP3 
  10. .LINK 
  11.     http://pshscripts.blogspot.com/2008/07/clear-stackps1.html 
  12. .EXAMPLE 
  13.     PSH [C:\foo]: . 'E:\PowerShellScriptLib\System.Collections.Stack\clear-stack.ps1 
  14.     Initially, 
  15.        Count    : 5 
  16.        Values: 
  17.     jumped 
  18.     fox 
  19.     brown 
  20.     quick 
  21.     The 
  22.     After Clear, 
  23.        Count    : 0 
  24.        Values: 
  25.  
  26. #> 
  27.  
  28. ## 
  29. # Start of script 
  30. ## 
  31.  
  32. # Create stack 
  33. $stack = new-object system.collections.stack 
  34. $Stack.Push( "The" ); 
  35. $Stack.Push( "quick" ); 
  36. $Stack.Push( "brown" ); 
  37. $Stack.Push( "fox" ); 
  38. $Stack.Push( "jumped" ); 
  39.  
  40. # Display the count and values of the Stack 
  41. "Initially," 
  42. "   Count    : {0}" -f $Stack.Count 
  43. "   Values:" 
  44. $Stack 
  45.  
  46. # Clear the Stack 
  47. $Stack.Clear() 
  48.  
  49. # Display the count and values of the Stack 
  50. "After Clear," 
  51. "   Count    : {0}" -f $Stack.Count 
  52. "   Values:" 
  53. $Stack 

This script creates a script and shows the impact of clearing the stack.

Attributed to: Thomas Lee

URL: http://pshscripts.blogspot.com/2008/07/clear-stackps1.html

Copyright 2012 PowerShell.com. All rights reserved.