'*************************************************************************
' Script Name - Group Policy Check
'
' Purpose     - Monitors that Group Policy can be successfully applied
'               
' (c) Copyright 2014, Microsoft Corporation, All Rights Reserved
' Proprietary and confidential to Microsoft Corporation              
'*************************************************************************

Option Explicit

SetLocale("en-us")

Sub Main()

  Dim oAPI, oBag, oShell, oShellExec, iResult, iInterval

  Set oAPI = CreateObject("Mom.ScriptAPI")
  Set oBag = oAPI.CreatePropertyBag()    

  On Error Resume Next

  Set oShell = CreateObject("Wscript.Shell")
  iResult = oShell.Run("gpupdate", 0, true)

  if (iResult &lt;&gt; 0) Then
      Set oShellExec = oShell.Exec("gpupdate")

      for iInterval = 0 to 30
        if oShellExec.Status = 0 then
            oBag.AddValue "State", "BAD" 
            oBag.AddValue "ErrorString", "Group Policy failed to refresh properly.  Gpupdate output: " &amp; vbCrLf &amp; vbCrLf &amp; oShellExec.StdOut.ReadAll  

            Call oAPI.Return(oBag)   
            Exit sub
        End if

        wscript.sleep(1000)
      Next

      oBag.AddValue "State", "BAD" 
      oBag.AddValue "ErrorString", "Group Policy failed to refresh properly.  Gpupdate exited with error code: " &amp; iResult        
  Else
      oBag.AddValue "State", "GOOD" 
  End If
 
  Call oAPI.Return(oBag)                                                        

End Sub

Call Main()   