Thursday 16 September 2010

Get-ArrayList.ps1

  1. <# 
  2. .SYNOPSIS 
  3.     This script demonstrates the use of the Systems.Collections.Arraylist class 
  4. .DESCRIPTION 
  5.     This script is a re-write of an MSDN sample script 
  6. .NOTES 
  7.     File Name  : get-arraylist.ps1 
  8.     Author     : Thomas Lee - tfl@psp.co.uk 
  9.     Requires   : PowerShell Version 2.0 
  10. .LINK 
  11.     This script posted to: 
  12.         http://pshscripts.blogspot.com/2010/09/get-arraylistps1.html 
  13.     MSDN sample posted tot: 
  14.         http://msdn.microsoft.com/en-us/library/system.collections.arraylist.aspx
  15. .EXAMPLE 
  16.     PSH [C:\foo]: .\Get-ArrayList.ps1 
  17.     0 
  18.     1 
  19.     2 
  20.     myAL 
  21.     Count       : 3 
  22.     Capacity    : 4 
  23.     Fixed Len?  : False 
  24.     Read only?  : False 
  25.     Values   : 
  26.     Hello 
  27.     World 
  28.     ! 
  29. #> 
  30.  
  31. # Creates and initializes a new ArrayList. 
  32. $myAL = New-Object System.Collections.ArrayList 
  33.  
  34. # Add three values 
  35. $myAL.Add("Hello"
  36. $myAL.Add("World"
  37. $myAL.Add("!"
  38.  
  39. # Display the properties and values of the ArrayList. 
  40. "myAL" 
  41. "Count       : {0}" -f $myAL.Count 
  42. "Capacity    : {0}" -f $myAL.Capacity 
  43. "Fixed Len?  : {0}" -f $myAL.IsFixedSize 
  44. "Read only?  : {0}" -f $myAL.IsReadOnly 
  45. "Values   :" 
  46. $myAL 

No comments: