Friday, 19 December 2008

Get-DomainModeEnumValues.ps1

 

  1. # Get-DomainModeEnumValues.ps1 
  2. # Prints out the values of the DomainMode Enum 
  3. # Thomas Lee - tfl@psp.co.uk 
  4.  
  5. # Enumerate System.DirectoryServices.ActiveDirectory.DomainMode 
  6.  
  7. $enums=[enum]::GetValues([System.DirectoryServices.ActiveDirectory.DomainMode]) 
  8.  
  9. # Display values 
  10. "System.Net.DirectoryServices.ActiveDirectory.DomainMode 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 = "Windows2008Domain" 
  17. if ($ToCheck -eq  [System.DirectoryServices.ActiveDirectory.DomainMode]::Windows2008Domain) { 
  18. "`$ToCheck is Windows2008Domain" 
  19.     } 
  20. else
  21.     "`$ToCheck is NOT Windows2008Domain" 
  22.     } 

This script produces the following output:

PS C:\Foo> .\Get-DomainModeEnumValues.ps1
System.Net.DirectoryServices.ActiveDirectory.DomainMode enum has 5 possible values:
Value 1: Windows2000MixedDomain
Value 2: Windows2000NativeDomain
Value 3: Windows2003InterimDomain
Value 4: Windows2003Domain
Value 5: Windows2008Domain

$ToCheck is Windows2008Domain

No comments: