Compares the GPO version number stored on two specified domain controllers for a specified GPO. Requires the Group Policy Management Console. Script contributed by Microsoft's Mike Stephens and Judith Herman.

Visual Basic
Edit|Remove
Const USE_THIS_DC = 0

strPolicyName ="New Group Policy Object"
strDC1 = "hq-con-srv-01"
strDC2 = "hq-con-srv-02"
strDomainName = "contoso.com"

' Do this for the first Domain Controller 
Set oGPM = CreateObject("GPMGMT.GPM")
Set oGPConst = oGPM.GetConstants()
Set oGPSearch = oGPM.CreateSearchCriteria()
Set oDom = oGPM.GetDomain( strDomainName, strDC1, USE_THIS_DC)

oGPSearch.Add oGPConst.SearchPropertyGPODisplayName, oGPConst.SearchOpEquals, strPolicyName
Set oGPSearchResults = oDom.SearchGPOs( oGPSearch)

If oGPSearchResults.Count <= 0 Then 
     WScript.Echo "The Group Policy object " & strPolicyName & " was not found!" & _
         VbCrLf & "on Domain Controller " & strDC1
     WScript.Quit()
End If 

Set oGPO = oGPSearchResults.Item(1)

strDC1UserVersion =  oGPO.UserDSVersionNumber
strDC1CompVersion =  oGPO.ComputerDSVersionNumber

' Do this for the Second Domain Controller
Set oGPM = CreateObject("GPMGMT.GPM")
Set oGPConst = oGPM.GetConstants()
Set oGPSearch = oGPM.CreateSearchCriteria()
Set oDom = oGPM.GetDomain( strDomainName, strDC2, USE_THIS_DC)

oGPSearch.Add oGPConst.SearchPropertyGPODisplayName, oGPConst.SearchOpEquals, strPolicyName
Set oGPSearchResults = oDom.SearchGPOs( oGPSearch)

If oGPSearchResults.Count <= 0 Then 
    WScript.Echo "The Group Policy object " & strPolicyName & " was not found!" & VbCrLf & _
        "on Domain Controller " & strDC2
    WScript.Quit()
End If 

Set oGPO = oGPSearchResults.Item(1)
strDC2UserVersion =  oGPO.UserDSVersionNumber
strDC2CompVersion =  oGPO.ComputerDSVersionNumber

If CLng(strDC1CompVersion) = CLng(strDC2CompVersion) Then
    result = "The computer policy version number for " & strDC1 & " and " & _
        strDC2 & " match." & VbCrLf
Else
    result = "The computer policy version number for " & strDC1 & " and " & _
        strDC2 & " do not match." & VbCrLf
End If 

If CLng(strDC1UserVersion) = CLng(strDC2UserVersion) Then
    result = result & "The user policy version number for " & strDC1 & " and " & _
        strDC2 & " match." & VbCrLf
Else
    result = result & "The user policy version number for " & strDC1 & " and " & _
        strDC2 & " do not match."
End If 

WScript.Echo result

WScript.Quit()