作成 2010.03.04
更新 2010.03.04
VBScript で Active Directory の機能レベルを調べる
On Error Resume Next
Dim baseDN, objRootDSE, objDomain
Dim intBehavior, arrBehavior(4), arrNativeOrMix(1)
Dim strResult

baseDN = ""
arrBehavior(0) = "Windows 2000 "
arrBehavior(1) = "Windows Server 2003 中間"
arrBehavior(2) = "Windows Server 2003"
arrBehavior(3) = "Windows Server 2008"
arrBehavior(4) = "Windows Server 2008 R2"
arrNativeOrMix(0) = "ネイティブ"
arrNativeOrMix(1) = "混在"

Set objRootDSE = GetObject("LDAP://rootDSE")
If Err.Number <> 0 Then
  WScript.Echo "ドメイン接続に失敗しました。終了します。"
  WScript.Quit
End If
baseDN = objRootDSE.Get("defaultNamingContext")

' Domain Functional Level
Set objDomain = GetObject("LDAP://" & baseDN)
objDomain.GetInfo
intBehavior = 0
strResult = "Domain:" & vbTab
On Error Resume Next
intBehavior = objDomain.Get("msDS-Behavior-Version")
If Err.Number <> 0 Or intBehavior = 0 Then
  intBehavior = objDomain.Get("nTMixedDomain")
  strResult = strResult & arrBehavior(0) & arrNativeOrMix(intBehavior)
ElseIf intBehavior > UBound(arrBehavior) Or intBehavior < 0Then
  strResult = strResult & "Unknown Level: " & intBehavior
Else
  strResult = strResult & arrBehavior(intBehavior)
End If
On Error Goto 0

' Forest Functional Level
intBehavior = 0
strResult = strResult & vbNewLine & "Forest:" & vbTab
Set objDomain = GetObject("LDAP://CN=Partitions,CN=Configuration," & baseDN)
objDomain.GetInfo
On Error Resume Next
intBehavior = objDomain.Get("msDS-Behavior-Version")
If Err.Number <> 0 Or intBehavior = 0 Then
  strResult = strResult & arrBehavior(0)
ElseIf intBehavior > UBound(arrBehavior) Or intBehavior < 0Then
  strResult = strResult & "Unknown Level: " & intBehavior
Else
  strResult = strResult & arrBehavior(intBehavior)
End If
On Error Goto 0

WScript.Echo strResult

©2004-2017 UPKEN IPv4