Wednesday 17 June 2009

Get-ConformanceLevelEnum.ps1


  1. <# 
  2. .SYNOPSIS 
  3.     This script demonstrates the confirmance level enum. 
  4. .DESCRIPTION 
  5.     This script displays the values form the conformancelevel enum 
  6.     and checks it against a value. 
  7. .NOTES 
  8.     File Name  : Get-ConformanceLevelEnum.ps1 
  9.     Author     : Thomas Lee - tfl@psp.co.uk 
  10.     Requires   : PowerShell V2 CTP3 
  11. .LINK 
  12.     This script posted to: 
  13.         http://pshscripts.blogspot.com 
  14.     MSDN Sample posted at: 
  15.         http://msdn.microsoft.com/en-us/library/h2344bs2(VS.85).aspx 
  16. .EXAMPLE 
  17.     PSH [C:\foo]: .\Get-ConformanceLevelEnum.ps1' 
  18.     System.XML.ConformanceLevel enum has 3 possible values 
  19.     Value 0: Auto 
  20.     Value 1: Fragment 
  21.     Value 2: Document 
  22.      
  23.     $ToCheck1 is NOT document 
  24.     $ToCheck2 is Document 
  25. #> 
  26.  
  27. ## 
  28. # Start of script 
  29. ## 
  30. # Demonstrates the ConformanceLevel enum 
  31. # Thomas Lee - tfl@psp.co.uk 
  32. # Enumerate the enum 
  33. $enums=[enum]::GetValues([System.Xml.ConformanceLevel]) 
  34.  
  35. # Display 
  36. "System.XML.ConformanceLevel enum has {0} possible values" -f $enums.count 
  37. $i=0 
  38. $enums| %{"Value {0}: {1}" -f $i,$_.tostring();$i++} 
  39. "" 
  40. # Checking against a an enum value  
  41. $ToCheck1 = "somethingelse" 
  42. $Tocheck2 = "document" 
  43. if ($ToCheck1 -eq  [System.XML.ConformanceLevel]::Document) { 
  44.   "`$ToCheck1 is document"
  45. else
  46.   "`$ToCheck1 is NOT document" 
  47.    
  48. if ($ToCheck2 -eq  [System.XML.ConformanceLevel]::Document) { 
  49.  "`$ToCheck2 is Document"
  50. else
  51.  "`$ToCheck2 is NOT document" 
  52. }  
  53. #End of Script 

2 comments:

LarryC said...

Values reported are one higher than actual.
$i should be initialized to zero for proper enumeration, ie: Auto=0, Fragment=1 and Document=2

Thomas Lee said...

@Larry - this is now fixed - thanks for the catch.