Saturday, October 25, 2008

ePO Duplicate GUID script

Here is a script that I have been asked about several times. You just have to put in your LDAP / OU structure, where you keep your computers and this will fix that problematic duplicate GUID problem.
'==========================================================================
'
' VBScript Source File -- Created with SAPIEN Technologies PrimalScript 4.0
'
'
' COMMENT: gets guids
'
'==========================================================================

'~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
'Define Constants
'~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Dim intRecCount
intRecCount = 0

LocalComputer = "."

''~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
''Create and load dictionary object
''~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
'Set objDictionary = CreateObject("Scripting.Dictionary")
'objDictionary.CompareMode = vbTextCompare
'Set objGUIDDict = CreateObject("Scripting.Dictionary")
'objGUIDDict.CompareMode = vbTextCompare
'
'
'
''~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
'' Determine DNS domain name.
''~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
'Set objRootDSE = GetObject("LDAP://RootDSE")
'strDNSDomain = objRootDSE.Get("DefaultNamingContext")
'
''~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
''Create connection and command objects
''~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
'Set objConnection = CreateObject("ADODB.Connection")
'objConnection.Open "Provider=ADsDSOObject;"
'Set objCommand = CreateObject("ADODB.Command")
'objCommand.ActiveConnection = objConnection
'objCommand.Properties("Page Size") = 100
'objCommand.Properties("Timeout") = 60
'objCommand.Properties("Cache Results") = False
'
'~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
'Define Search Query
'~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
'strBase = ""
'strFilter = "(&(objectCategory=person)(objectClass=user))"
'strFilter = "(objectCategory=computer)"
'strAttributes = "name,userAccountControl"
'strQuery = strBase & ";" & strFilter & ";" & strAttributes
'
''~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
''Execute command and build recordset
''~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
'objCommand.CommandText = strQuery
'Set objRecordSet = objCommand.Execute
'Wscript.echo "-----------------------------------------------------"
'Wscript.echo "Running AD Query ..."
'Do until objRecordSet.EOF
' intRecCount = intRecCount + 1
' 'Wscript.StdOut.Write(".")
' strCN = objRecordSet.Fields("name")
' intUAC=objRecordSet.Fields("userAccountControl")
' if intUAC AND ADS_UF_ACCOUNTDISABLE Then
' AcctStat="Disabled"
' Else
' AcctStat="Enabled"
' End If
' If AcctStat="Enabled" Then
' errValue = Ping(strCN)
' If errValue = "Online" Then
' 'WScript.Echo strCN
' strRegValue=RegListValueString(strCN)
' 'WScript.Echo strRegValue
' 'add items to dictionary
' 'objDictionary.add strCN, strRegValue
' If strRegValue="" Or IsNull(strRegValue) Then
' WScript.Echo strCN & " " & strRegValue & " - Null"
' ElseIf objGUIDDict.Exists(strRegValue) Then
' WScript.Echo strCN & " " & strRegValue & " - Duplicate"
' Call RegDeleteValue(strCN)
' Call StopService(strCN,"McAfeeFramework")
' Call StartService(strCN,"McAfeeFramework")
' On Error Resume Next
' Set osvcRemote = GetObject("winmgmts:\\" & strCN & "\root\cimv2")
' Set oprocess = osvcRemote.Get("win32_process")
' ret = oprocess.create("c:\\program files\\network associates\\common framework\\cmdagent.exe /P")
' if (ret <> 0) Then
' 'wscript.echo "Failed to start process on " & strCN & ": " & ret
' Else
' 'wscript.echo "Started process on " & strCN & ": " & ret
' End If
' Else
' objGUIDDict(strRegValue) = True
' WScript.Echo strCN & " " & strRegValue & " - Healthy"
' End If
' End If
' End If
' objRecordSet.movenext
'Loop
'WScript.Quit
'
''~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
''Build a dictionary of the unique GUIDS
''~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
'For Each GUID in objDictionary.Items
' 'WScript.Echo GUID
' objGUIDDict(GUID) = True
'Next
'
''~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
''Compare guids to computernames and return all computers for each guid
''~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
'For Each strMgrName In OBJGUIDDICT.Keys
' strMbxName = ""
' index = 0
' ReDim arrayGUIDS(0, index)
' For Each strMbxName In OBJDICTIONARY
' If OBJDICTIONARY.item(strMbxName) = strMgrName Then
' 'WScript.Echo "Matched guid " & strMgrName & " " & strMBXName
' ReDim Preserve arrayGUIDS(0, index)
' arrayGUIDS(0, index) = strMBXName
' index = index + 1
' End If
' Next
' If index > 1 Then
' WScript.Echo strMgrName & " has more then 1 member."
' For Each strcomputername In arrayguids
' WScript.Echo strcomputername
' call RegDeleteValue(strComputername)
' call StopService(strcomputername,"McAfeeFramework")
' Call StartService(strcomputername,"McAfeeFramework")
' On Error Resume Next
' Set osvcRemote = GetObject("winmgmts:\\" & strcomputername & "\root\cimv2")
' Set oprocess = osvcRemote.Get("win32_process")
' ret = oprocess.create("c:\\program files\\network associates\\common framework\\cmdagent.exe /P")
' if (ret <> 0) Then
' wscript.echo "Failed to start process on " & strcomputername & ": " & ret
' Else
' wscript.echo "Started process on " & strcomputername & ": " & ret
' End If
' Err.Clear
' Next
' End If
'Next
'
'wscript.echo "Completed query - total records: " & intRecCount
'
'Function RegListValueString(strComputer)
' On Error Resume Next
' Const HKEY_LOCAL_MACHINE = &H80000002
' strKeyPath = "SOFTWARE\Network Associates\ePolicy Orchestrator\Agent"
' strValueName = "AgentGUID"
' Set oReg=GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & _
' strComputer & "\root\default:StdRegProv")
'
' oReg.GetStringValue HKEY_LOCAL_MACHINE,strKeyPath,strValueName,strValue
' RegListValueString = strValue
'End Function
'
'Function RegDeleteValue(strComputer)
' On Error Resume Next
' Const HKEY_LOCAL_MACHINE = &H80000002
' strKeyPath = "SOFTWARE\Network Associates\ePolicy Orchestrator\Agent"
' strValueName = "AgentGUID"
' Set oReg=GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & _
' strComputer & "\root\default:StdRegProv")
'
' oReg.DeleteValue HKEY_LOCAL_MACHINE,strKeyPath,strValueName
'End Function
'
'Function Ping(remoteComputer)
' Set objWMIService = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & LocalComputer & "\root\cimv2")
' Set colPingedComputers = objWMIService.ExecQuery("Select * from Win32_PingStatus Where Address = '" & remoteComputer & "'")
'
' For Each objComputer in colPingedComputers
' If objComputer.StatusCode = 0 Then
' Ping = "Online"
' Else
' Ping = "Offline"
' End If
' Next
' End Function
'
'
'Function StopService(strComputer, Service)
' On Error Resume Next
' Set objWMIService = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
' Set colServiceList = objWMIService.ExecQuery("Associators of " _
' & "{Win32_Service.Name='" & Service & "'} Where " _
& "AssocClass=Win32_DependentService " & "Role=Antecedent" )
' On Error Resume Next
' For Each objService in colServiceList
' If (objService.State = "Stopped") Then
' 'wscript.echo "Dependant service " & objService.name & " is " & objService.State
' Exit For
' End If
' 'wscript.echo "Stopping dependent service: " & objService.Name & " ..."
' objService.StopService()
' wscript.sleep 1000
' Next
' wscript.sleep 2000
'
' Set colServiceList = objWMIService.ExecQuery("Select * from Win32_Service where Name= '" & Service & "'")
' For Each objService in colServiceList
' If (objService.State = "Stopped") Then
' 'wscript.echo objService.name & " service is " & objService.State
' Exit For
' End If
' 'wscript.echo "Stopping " & Service & " service ..."
' errReturn = objService.StopService()
' Next
'End Function
'
'Function StartService(strComputer, Service)
' On Error Resume Next
' Set objWMIService = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
' Set colServiceList = objWMIService.ExecQuery("Select * from Win32_Service where Name= '" & Service & "'")
'
' For Each objService in colServiceList
' If (objService.State = "Running") Then
' 'wscript.echo objService.name & " service is " & objService.State
' Exit For
' End If
' 'wscript.echo "Starting " & Service & " ..."
' errReturn = objService.StartService()
' Set colDepServiceList = objWMIService.ExecQuery("Associators of " _
' & "{Win32_Service.Name='" & Service & "'} Where " _
' & "AssocClass=Win32_DependentService " & "Role=Antecedent" )
' For Each objDepService in colDepServiceList
' If (objDepService.State = "Running") Then
' wscript.echo "Dependant service " & objDepService.name & " is " & objDepService.State
' Exit For
' End If
' 'wscript.echo "Starting dependent service: " & objDepService.Name & " service ..."
' objDepService.StartService()
' Next
' Next
' wscript.sleep 2000
'End Function

This will check the system, keep track of the GUID and replace it if there is a duplicate.

4 comments:

Anonymous said...

Please excuse me if this is a dumb question, but what scripting language are you using for this?

Very Lost said...

This is a simple VBS script. You will have to take out the first set of ' in order to make it run.

Anonymous said...

One more dumb question.. Where do you place your LDAP/OU structure? I don't see the normal strings for that.

Very Lost said...

It is in the "Define Search Query" area.