Show-QueueProperties


posted by ps3
07-22-2009

Downloads: 326
File size: 1.5kB
Views: 789

Embed
Show-QueueProperties
  1. <# 
  2. .SYNOPSIS 
  3.     Demonstrates using a queue object 
  4. .DESCRIPTION 
  5.     This script creates a queue, then adds some items to it, print 
  6.     out the contents then synchs it. 
  7. .NOTES 
  8.     File Name  : show-queueproperties.ps1 
  9.     Author     : Thomas Lee - tfl@psp.co.uk 
  10.     Requires   : PowerShell V2 CTP3 
  11.     Tags       : showqueue,enqueue,synchronize,system.collections.queue 
  12.  
  13. .LINK 
  14.     http://www.pshscripts.blogspot.com 
  15. .EXAMPLE 
  16.     PS c:\foo> .\show-queueproperties.ps1 
  17.     Creating and populating $myq object with... 
  18.     3 entries in the queue as follows: 
  19.     entry 0:  Hello 
  20.     entry 1:  World 
  21.     entry 2:  Jerry Garcia Rocks!! 
  22.  
  23.     Report on $myq 
  24.     $myq is synchronised?  :False 
  25.  
  26.     Synchronising $myq to $sq 
  27.     $sq  is synchronised?  :True     
  28. #> 
  29.  
  30. ## 
  31. #  Start of script 
  32. ## 
  33.  
  34. # Create new queue object 
  35. $myq = new-object System.Collections.Queue 
  36. $myq.Enqueue("Hello"
  37. $myq.Enqueue("World"
  38. # or a more powershell way 
  39. $myq += "Jerry Garcia Rocks!!" 
  40.  
  41. # Show use of the properties of the Queue 
  42. # First use count property 
  43. "Creating and populating `$myq object with..." 
  44. $i=
  45. "`{0} entries in the queue as follows:" -f $myq.Count 
  46. $myq | % {"entry {0}:  {1}" -f $i++,$_
  47. "" 
  48.  
  49. # Now check synchronisation 
  50. "Report on `$myq" 
  51. "`$myq is synchronised?  :{0}" -f $myq.IsSynchronized 
  52. "" 
  53.  
  54. # Synch the queue 
  55. "Synchronising `$myq to `$sq" 
  56. $sq = [system.collections.queue]::synchronized($myq
  57.  
  58. # report again 
  59. "`$sq  is synchronised?  :{0}" -f $sq.IsSynchronized 
  60. # End Script 

This script creates a queue, adds some items to it, prints out the contents, then syncs it.

Attributed to: Thomas Lee

URL: http://www.pshscripts.blogspot.com

Copyright 2012 PowerShell.com. All rights reserved.