Thursday, 18 December 2008

Get-ForestModeEnumValues.ps1

 

  1. # Get-ForestModeEnumValues.ps1 
  2. # Prints out the values of the ForestMode Enum 
  3. # Thomas Lee - tfl@psp.co.uk 
  4.  
  5. # Enumerate System.DirectoryServices.ActiveDirectory.forestmode 
  6.  
  7. $enums=[enum]::GetValues([System.DirectoryServices.ActiveDirectory.ForestMode]) 
  8.  
  9. # Display values 
  10. "System.Net.DirectoryServices.ActiveDirectory.Forest mode enum has {0} possible values:" -f $enums.count 
  11. $i=1 
  12. $enums | %{"Value {0}: {1}" -f $i,$_.tostring();$i++} 
  13. ""  
  14.  
  15. # Checking against an enum value  
  16. $ToCheck = "Windows2008Forest" 
  17. if ($ToCheck -eq  [System.DirectoryServices.ActiveDirectory.ForestMode]::Windows2008Forest) { 
  18. "`$ToCheck is Windows2008Forest" 
  19.     } 
  20. else
  21.     "`$ToCheck is NOT Windows2008Forest" 
  22.     } 

This script produces the following output:

PS C:\foo> .\Get-ForestModeEnumValues.ps1
System.Net.DirectoryServices.ActiveDirectory.Forest mode enum has 4 possible values:
Value 1: Windows2000Forest
Value 2: Windows2003InterimForest
Value 3: Windows2003Forest
Value 4: Windows2008Forest

$ToCheck is Windows2008Forest

No comments: