home *** CD-ROM | disk | FTP | other *** search
/ Chip 2001 May / W2KPRK.iso / compmgmt.cab / SchemaDiff.vbs < prev    next >
Text File  |  1999-11-04  |  26KB  |  769 lines

  1.  
  2. '********************************************************************
  3. '*
  4. '* File:        SCHEMADIFF.VBS
  5. '* Created:     April 1999
  6. '* Version:     1.0
  7. '*
  8. '* Main Function: Compares the schema between two different enterprises
  9. '* Usage: SCHEMADIFF.VBS [/U:username] [/W:password] [/D:domain] [/S:server] [/F:file name] [/Q]
  10. '*
  11. '* Copyright (C) 1999 Microsoft Corporation
  12. '*
  13. '********************************************************************
  14.  
  15. OPTION EXPLICIT
  16. ON ERROR RESUME NEXT
  17.  
  18. 'Define constants
  19. CONST CONST_STRING_NOT_FOUND            = -1
  20. CONST CONST_ERROR                       = 0
  21. CONST CONST_WSCRIPT                     = 1
  22. CONST CONST_CSCRIPT                     = 2
  23. CONST CONST_SHOW_USAGE                  = 3
  24. CONST CONST_PROCEED                     = 4
  25.  
  26. CONST ForWriting            = 2
  27. CONST ForAppending            = 8
  28.  
  29. CONST ADS_OBJECT_NOTFOUND               = &H80072030
  30. CONST ADS_ATTRIBUTE_NOTFOUND        = &H8007000A
  31.  
  32. 'Declare variables
  33. Dim strFile, strCurrentUser, strPassword, blnQuiet, intOpMode, i
  34. Dim strArgumentArray, strServer
  35. ReDim strArgumentArray(0)
  36.  
  37. 'Initialize variables
  38. intOpMode = 0
  39. blnQuiet = False
  40. strFile = ""
  41. strCurrentUser = ""
  42. strPassword = ""
  43. strServer = ""
  44. strArgumentArray(0) = ""
  45.  
  46.  
  47. 'Get the command line arguments
  48. For i = 0 to Wscript.arguments.count - 1
  49.     ReDim Preserve strArgumentArray(i)
  50.     strArgumentArray(i) = Wscript.arguments.item(i)
  51. Next
  52.  
  53. 'Check whether the script is run using CScript
  54. Select Case intChkProgram()
  55.     Case CONST_CSCRIPT
  56.         'Do Nothing
  57.     Case CONST_WSCRIPT
  58.         WScript.Echo "Please run this script using CScript." & vbCRLF & _
  59.             "This can be achieved by" & vbCRLF & _
  60.             "1. Using ""CScript DISPLAYOLD.VBS arguments"" for Windows 95/98 or" & vbCRLF & _
  61.             "2. Changing the default Windows Scripting Host setting to CScript" & vbCRLF & _
  62.             "    using ""CScript //H:CScript //S"" and running the script using" & vbCRLF & _
  63.             "    ""SCHEMADIFF.VBS arguments"" for Windows NT."
  64.         WScript.Quit
  65.     Case Else
  66.         WScript.Quit
  67. End Select
  68.  
  69. 'Parse the command line
  70. intOpMode = intParseCmdLine(strArgumentArray, strCurrentUser,strPassword, blnQuiet, strServer, strFile)
  71. If Err.Number Then
  72.     WScript.Echo "Error 0x" & CStr(Hex(Err.Number)) & " occurred in parsing the command line."
  73.     If Err.Description <> "" Then  WScript.Echo "Error description: " & Err.Description 
  74.     WScript.quit
  75. End If
  76.  
  77. Select Case intOpMode
  78.     Case CONST_SHOW_USAGE
  79.         Call ShowUsage()
  80.     Case CONST_PROCEED
  81.         Call SCHEMADIFF(strServer, strCurrentUser, strPassword, blnQuiet, strFile)
  82.     Case CONST_ERROR
  83.         'Do nothing.
  84.     Case Else
  85.         Wscript.Echo "Error occurred in passing parameters."
  86. End Select
  87.  
  88. WScript.Quit
  89.  
  90. '********************************************************************
  91. '*
  92. '* Function intChkProgram()
  93. '* Purpose: Determines which program is used to run this script.
  94. '* Input:   None
  95. '* Output:  intChkProgram is set to one of CONST_ERROR, CONST_WSCRIPT,
  96. '*          and CONST_CSCRIPT.
  97. '*
  98. '********************************************************************
  99.  
  100. Private Function intChkProgram()
  101.  
  102.     ON ERROR RESUME NEXT
  103.  
  104.     Dim strFullName, strCommand, i, j
  105.  
  106.     'strFullName should be something like C:\WINDOWS\COMMAND\CSCRIPT.EXE
  107.     strFullName = WScript.FullName
  108.     If Err.Number then
  109.         WScript.Echo "Error 0x" & CStr(Hex(Err.Number)) & " occurred."
  110.         If Err.Description <> "" Then WScript.Echo "Error description: " & Err.Description 
  111.         intChkProgram =  CONST_ERROR
  112.         Exit Function
  113.     End If
  114.  
  115.     i = InStr(1, strFullName, ".exe", 1)
  116.     If i = 0 Then
  117.         intChkProgram =  CONST_ERROR
  118.         Exit Function
  119.     Else
  120.         j = InStrRev(strFullName, "\", i, 1)
  121.         If j = 0 Then
  122.             intChkProgram =  CONST_ERROR
  123.             Exit Function
  124.         Else
  125.             strCommand = Mid(strFullName, j+1, i-j-1)
  126.             Select Case LCase(strCommand)
  127.                 Case "cscript"
  128.                     intChkProgram = CONST_CSCRIPT
  129.                 Case "wscript"
  130.                     intChkProgram = CONST_WSCRIPT
  131.                 Case Else       'should never happen
  132.                     WScript.Echo "An unexpected program is used to run this script."
  133.                     WScript.Echo "Only CScript.Exe or WScript.Exe can be used to run this script."
  134.                     intChkProgram = CONST_ERROR
  135.             End Select
  136.         End If
  137.     End If
  138.  
  139. End Function
  140.  
  141. '********************************************************************
  142. '*
  143. '* Function intParseCmdLine()
  144. '* Purpose: Parses the command line.
  145. '* Input:   strArgumentArray    an array containing input from the command line
  146. '* Output: strFile                 the output file name
  147. '*             strCurrentUser    the name or cn of the user for the destination domain
  148. '*             strPassword        the password for the user in the destination domain
  149. '*             blnQuiet              specifies whether to suppress messages
  150. '*             strServer             the destination server name
  151. '*             intParseCmdLine     is set to one of CONST_ERROR, CONST_SHOW_USAGE, CONST_PROCEED.
  152. '*
  153. '********************************************************************
  154.  
  155. Private Function intParseCmdLine(strArgumentArray, strCurrentUser,strPassword, blnQuiet, strServer, strFile)
  156.  
  157.     ON ERROR RESUME NEXT
  158.  
  159.     Dim i, j, strFlag
  160.  
  161.     intParseCmdLine = CONST_PROCEED
  162.  
  163.     strFlag = strArgumentArray(0)
  164.     If strFlag = "" then                    'No arguments have been received
  165.     intParseCmdLine = CONST_SHOW_USAGE
  166.         Exit Function
  167.     End If
  168.  
  169.     'online help was requested
  170.     If (strFlag="/help") OR (strFlag="/HELP") OR (strFlag="/h") OR (strFlag="\h") OR (strFlag="-h") _
  171.         OR (strFlag = "\?") OR (strFlag = "/?") OR (strFlag = "?") OR (strFlag="h") Then
  172.         intParseCmdLine = CONST_SHOW_USAGE
  173.         Exit Function
  174.     End If
  175.  
  176.     j = 0
  177.     For i = 0 to UBound(strArgumentArray)
  178.         strFlag = Left(strArgumentArray(i), InStr(1, strArgumentArray(i), ":")-1)
  179.         If Err.Number Then            'An error occurs If there is no : in the string
  180.             Err.Clear
  181.             Select Case LCase(strArgumentArray(i))
  182.                 Case "/q" 
  183.                   blnQuiet = True
  184.                 Case Else
  185.                   WScript.Echo strArgumentArray(i) & " is NOT recognized as a valid input."
  186.                   intParseCmdLine = CONST_ERROR
  187.                   Exit Function
  188.             End Select 'end processing args that have no params
  189.  
  190.         Else
  191.             Select Case LCase(strFlag)
  192.                 Case "/u"
  193.                     strCurrentUser = Right(strArgumentArray(i), Len(strArgumentArray(i))-3)
  194.                 Case "/w"
  195.                     strPassword = Right(strArgumentArray(i), Len(strArgumentArray(i))-3)
  196.                 Case "/s"
  197.                     strServer = Right(strArgumentArray(i), Len(strArgumentArray(i))-3)
  198.                 Case "/f"
  199.         strFile = Right(strArgumentArray(i), Len(strArgumentArray(i))-3)
  200.                 Case else
  201.                   WScript.Echo strArgumentArray(i) & " is not recognized as a valid input."
  202.                   intParseCmdLine = CONST_ERROR
  203.                   Exit Function
  204.             End Select
  205.         End If
  206.     Next
  207.  
  208.    If Len(strCurrentUser) = 0 Then
  209.       WScript.Echo "User name not supplied using /u switch"    
  210.       intParseCmdLine = CONST_SHOW_USAGE
  211.    End If
  212.  
  213.    If Len(strServer) = 0 Then
  214.       WScript.Echo "Server name not supplied using /s switch"    
  215.       intParseCmdLine = CONST_SHOW_USAGE
  216.    End If
  217.  
  218.  
  219. End Function
  220.  
  221. '********************************************************************
  222. '*
  223. '* Sub ShowUsage()
  224. '* Purpose:   Shows the correct usage to the user.
  225. '* Input:     None
  226. '* Output:    Help messages are displayed on screen.
  227. '*
  228. '********************************************************************
  229.  
  230. Sub ShowUsage()
  231.  
  232.     Wscript.echo ""
  233.     Wscript.echo "SCHEMADIFF.VBS    Compares schema on two different domains."  & vbCRLF
  234.     Wscript.echo "SCHEMADIFF.VBS /U:username /W:password /S:server [/F:filename] [/Q]"
  235.     Wscript.echo " command line switches:"
  236.     Wscript.echo "   /? /H /HELP    Displays this help message."
  237.     Wscript.echo " command line parameters:"
  238.     Wscript.echo "   /U:Username    Username for destination domain."
  239.     Wscript.echo "   /W:Password    Password for destination domain."
  240.     WScript.echo "   /S:Server      Name of destination domain controller."
  241.     Wscript.echo "   /F:Filename    Valid filename for output file. (optional)" 
  242.     WScript.echo ""
  243.     Wscript.echo "EXAMPLES:"
  244.     WScript.echo ""
  245.     Wscript.echo "CSCRIPT SCHEMADIFF  /S:wombat.acme.com /U:Administrator /W:password"
  246.     WScript.echo "   compares the schema for the domain of the currently logged on user with the"
  247.     WScript.echo "   schema for the domain of which wombat.acme.com is a domain controller."
  248. End Sub
  249.  
  250. '********************************************************************
  251. '* Sub    SCHEMADIFF()
  252. '* Purpose    compares two schemas
  253. '* Input        strServer    Name of the domain controller
  254. '*        strCurrentUser    User credentials
  255. '*        strPassword    User password
  256. '*        blnQuiet
  257. '*        strFile        Name of output file
  258. '*        
  259. '* Output    None
  260. '*        Displays differences
  261. '*        Optionally writes output to strFile
  262. '*
  263. '********************************************************************
  264. Sub SchemaDiff(strServer, strCurrentUser, strPassword, blnQuiet, strFile)
  265.  
  266. ON ERROR RESUME NEXT
  267.  
  268.     Dim objSrcSchema, strSrcSchema, strSrcServer, objSrcClass
  269.      Dim objRoot, objFileSystem, objFile, objProvider, blnMatch
  270.      Dim objDstSchema, strDstSchema, strDstServer, objDstClass
  271.     Dim iSrcSchemaVersion, iDstSchemaVersion
  272.  
  273.     Dim objADO, objADOCommand, strFilter, strResults, strSearch, rsADO, iCount, arrTemp
  274.     
  275.     blnMatch = True
  276.  
  277.     If strFile = "" Then
  278.                 objFile = ""
  279.         Else
  280.                 'Create a filesystem object
  281.                 Set objFileSystem = CreateObject("Scripting.FileSystemObject")
  282.                 If Err.Number Then
  283.                         WScript.Echo "Error 0x" & CStr(Hex(Err.Number)) & " opening a filesystem object."
  284.                         If Err.Description <> "" Then WScript.Echo "Error description: " & Err.Description & "."
  285.             Err.Clear                    
  286.                     Else
  287.        
  288.                                'Open the file for output
  289.                         Set objFile = objFileSystem.OpenTextFile(strFile, 2, True)
  290.                         If Err.Number then
  291.                                         WScript.Echo "Error 0x" & CStr(Hex(Err.Number)) & " opening file " & strFile
  292.                                         If Err.Description <> "" Then WScript.Echo "Error description: " & Err.Description & "." 
  293.                 Err.Clear
  294.                                 End If
  295.                     End If
  296.     End If
  297.     
  298.     'bind to source schema
  299.     Set objRoot = GetObject("LDAP://RootDSE")    
  300.     If Err.Number then
  301.         WScript.Echo "Error 0x" & CStr(Hex(Err.Number)) & " occurred in binding to Source RootDSE."
  302.         If Err.Description <> "" Then WScript.Echo "Error description: " & Err.Description 
  303.         Err.Clear
  304.                 Exit Sub
  305.     End If
  306.                strSrcSchema = objRoot.Get("schemaNamingContext")
  307.                strSrcServer = objRoot.Get("dnsHostName") & "/"
  308.  
  309.                If blnQuiet Then WScript.Echo "Source Schema: " & strSrcSchema
  310.                If blnQuiet Then WScript.Echo "Source Server: " & strSrcServer
  311.  
  312.     Set objSrcSchema = GetObject("LDAP://" & strSrcServer & strSrcSchema)
  313.     If Err.Number then
  314.         WScript.Echo "Error 0x" & CStr(Hex(Err.Number)) & " occurred in binding to Source Schema NC. "
  315.         If Err.Description <> "" Then WScript.Echo "Error description: " & Err.Description 
  316.         Err.Clear
  317.             Exit Sub
  318.     End If
  319.  
  320.     iSrcSchemaVersion = objSrcSchema.objectVersion
  321.  
  322.     'bind to destination schema
  323.  
  324.     If Len(strServer) > 0 Then strServer = strServer & "/"
  325.  
  326.     Set objRoot = GetObject("LDAP://" & strServer & "RootDSE")
  327.     If Err.Number then
  328.         WScript.Echo "Error 0x" & CStr(Hex(Err.Number)) & " occurred in binding to Destination RootDSE."
  329.         If Err.Description <> "" Then WScript.Echo "Error description: " & Err.Description 
  330.         Err.Clear
  331.             Exit Sub
  332.     End If
  333.     
  334.     strServer = objRoot.Get("dnsHostName") & "/"
  335.  
  336.     'get schema
  337.  
  338.     strDstSchema = objRoot.Get("schemaNamingContext")
  339.  
  340.                 If blnQuiet Then WScript.Echo "Dest Schema: " & strDstSchema
  341.                 If blnQuiet Then WScript.Echo "Dest Server: " & strServer
  342.  
  343.     If strCurrentUser = "" Then            'no user credential is passed
  344.             Set objDstSchema = GetObject("LDAP://" & strServer & strDstSchema)
  345.     Else
  346.             Set objProvider = GetObject("LDAP:")
  347.         'Use user authentication
  348.  
  349.         Set objDstSchema = objProvider.OpenDsObject("LDAP://" & strServer & strDstSchema, strCurrentUser, strPassword,1)
  350.     End If
  351.     If Err.Number then
  352.         WScript.Echo "Error 0x" & CStr(Hex(Err.Number)) & " occurred in binding to Dest Schema NC. "
  353.         If Err.Description <> "" Then WScript.Echo "Error description: " & Err.Description 
  354.         Err.Clear
  355.             Exit Sub
  356.     End If
  357.  
  358.     iDstSchemaVersion = objDstSchema.objectVersion
  359.  
  360.      'create ADO search for destination
  361.  
  362.     Set objADO = CreateObject("ADODB.Connection")
  363.     If Err.Number then
  364.         WScript.Echo "Error 0x" & CStr(Hex(Err.Number)) & " occurred in creating ADO Connection. "
  365.         If Err.Description <> "" Then WScript.Echo "Error description: " & Err.Description 
  366.         Err.Clear
  367.             Exit Sub
  368.     End If
  369.  
  370.     objADO.Provider = "ADsDSOObject"
  371.  
  372.     If Len(strCurrentUser) > 0 Then 
  373.         objADO.Properties("User ID") = strCurrentUser
  374.         objADO.Properties("Password") = strPassword
  375.         objADO.Properties("Encrypt Password") = True
  376.     End If
  377.  
  378.     objADO.Open "STUFF"
  379.     If Err.Number then
  380.         WScript.Echo "Error 0x" & CStr(Hex(Err.Number)) & " occurred in opening ADO Connection. "
  381.         If Err.Description <> "" Then WScript.Echo "Error description: " & Err.Description 
  382.         Err.Clear
  383.             Exit Sub
  384.     End If
  385.  
  386.     Set objADOCommand = CreateObject("ADODB.Command")
  387.     If Err.Number then
  388.         WScript.Echo "Error 0x" & CStr(Hex(Err.Number)) & " occurred in creating ADO Command. "
  389.         If Err.Description <> "" Then WScript.Echo "Error description: " & Err.Description 
  390.         Err.Clear
  391.             Exit Sub
  392.     End If
  393.  
  394.     Set objADOCommand.ActiveConnection = objADO
  395.     If Err.Number then
  396.         WScript.Echo "Error 0x" & CStr(Hex(Err.Number)) & " occurred in opening ADO Connection. "
  397.         If Err.Description <> "" Then WScript.Echo "Error description: " & Err.Description 
  398.         Err.Clear
  399.             Exit Sub
  400.     End If
  401.  
  402.  
  403.     objADOCommand.Properties("Timeout")=0
  404.     objADOCommand.Properties("Time Limit")=0
  405.     objADOCommand.Properties("Page Size")=100
  406.     objADOCommand.Properties("Chase Referrals") = True
  407.  
  408.     WScript.Echo "Src Schema Version: " & iSrcSchemaVersion
  409.     WScript.Echo "Dst Schema Version: " & iDstSchemaVersion
  410.     
  411.     If isObject(objFile) Then 
  412.         objFile.WriteLine  "Src Schema Version: " & iSrcSchemaVersion
  413.         objFile.WriteLine  "Dst Schema Version: " & iDstSchemaVersion
  414.     End If
  415.  
  416.                 objSrcSchema.Filter=Array("classSchema")
  417.                 For Each objSrcClass in objSrcSchema
  418.         If Err.Number then
  419.             WScript.Echo "Error 0x" & CStr(Hex(Err.Number)) & " occurred enumerating classes. "
  420.             If Err.Description <> "" Then WScript.Echo "Error description: " & Err.Description 
  421.             Err.Clear
  422.                     Exit Sub
  423.         End If
  424.  
  425.         
  426.         If blnQuiet Then WScript.Echo "Class: " & objSrcClass.ldapDisplayName
  427.         If isObject(objFile) Then objFile.WriteLine "Class: " & objSrcClass.ldapDisplayName
  428.  
  429.         strFilter = "(&(objectClass=classSchema)(ldapDisplayName=" & objSrcClass.ldapDisplayName & "))"
  430.         strResults = "cn,ldapDisplayName,governsID,systemMayContain,systemMustContain"
  431.         strSearch = "<LDAP://" & strServer & strDstSchema & ">"
  432.  
  433.         objADOCommand.CommandText = strSearch & ";" & strFilter & ";" & strResults & ";subtree"
  434.                                 
  435.         Set rsADO = objADOCommand.Execute
  436.  
  437.         If Err.Number then
  438.             WScript.Echo "Error 0x" & CStr(Hex(Err.Number)) & " occurred in executing ADO Query. "
  439.             If Err.Description <> "" Then WScript.Echo "Error description: " & Err.Description 
  440.             Err.Clear
  441.                     Exit Sub
  442.         End If
  443.  
  444.         
  445.         
  446.         If rsADO.RecordCount > 0 Then
  447.  
  448.             While Not rsADO.EOF
  449.                 If blnQuiet Then WScript.Echo rsADO.Fields(1).Value & " found"
  450.                 If blnQuiet Then WScript.Echo "Src OID: " & objSrcClass.governsID
  451.  
  452.                                                                 If StrComp(rsADO.Fields(2).Value,objSrcClass.governsID) <> 0 Then
  453.                     WScript.Echo "Dst OID: " & rsADO.Fields(2).Value
  454.                     blnMatch=False
  455.                     If isObject(objFile) Then objFile.WriteLine "Dst OID: " & rsADO.Fields(2).Value
  456.                 Else
  457.                     If blnQuiet Then WScript.Echo "Src and Dst OID match"
  458.                 End If
  459.  
  460.                                                                 If Compare2Arrays(objSrcClass.systemMayContain,rsADO.Fields(3).Value) <>CONST_PROCEED Then
  461.                     WScript.Echo "Dst systemMayContain mismatch "
  462.                     blnMatch=False
  463.                     If isObject(objFile) Then  objFile.WriteLine "Dst systemMayContain mismatch"
  464.  
  465.                 Else
  466.                     if blnQuiet Then WScript.Echo "systemMayContain OK"
  467.                 End If
  468.  
  469.                 If Compare2Arrays(objSrcClass.systemMustContain,rsADO.Fields(4).Value) <>CONST_PROCEED Then
  470.                     WScript.Echo "Dst systemMustContain mismatch"
  471.                     blnMatch=False
  472.                     If isObject(objFile) Then  objFile.WriteLine "Dst systemMustContain mismatch"
  473.                 Else
  474.                     if blnQuiet Then WScript.Echo "systemMustContain OK"
  475.                 End If
  476.  
  477.                 rsADO.MoveNext
  478.             Wend
  479.         
  480.  
  481.         Else
  482.             WScript.Echo "Missing Class " & objSrcClass.ldapDisplayName
  483.             blnMatch=False
  484.             If isObject(objFile) Then objFile.WriteLine "Missing Class " & objSrcClass.ldapDisplayName
  485.             If Err.Number then
  486.                 WScript.Echo "Error 0x" & CStr(Hex(Err.Number)) & " occurred in missing class. "
  487.                 If Err.Description <> "" Then WScript.Echo "Error description: " & Err.Description 
  488.                 Err.Clear
  489.             End If
  490.         End If
  491.     Next
  492.     
  493.     'now search for attributes
  494.     WScript.Echo "Searching attributes"
  495.  
  496.                 objSrcSchema.Filter=Array("attributeSchema")
  497.     
  498.                 For Each objSrcClass in objSrcSchema
  499.         If Err.Number then
  500.             WScript.Echo "Error 0x" & CStr(Hex(Err.Number)) & " occurred enumerating attributes. "
  501.             If Err.Description <> "" Then WScript.Echo "Error description: " & Err.Description 
  502.             Err.Clear
  503.                     Exit Sub
  504.         End If
  505.         If blnQuiet Then WScript.Echo "Attribute: " & objSrcClass.ldapDisplayName
  506.         If isObject(objFile) Then objFile.WriteLine "Class: " & objSrcClass.ldapDisplayName
  507.  
  508.         strFilter = "(&(objectCategory=attributeSchema)(ldapDisplayName=" & objSrcClass.ldapDisplayName & "))"
  509.         strResults = "cn,ldapDisplayName,attributeID,attributeSyntax,rangeLower,rangeUpper"
  510.         strSearch = "<LDAP://" & strServer & strDstSchema & ">"
  511.         objADOCommand.CommandText = strSearch & ";" & strFilter & ";" & strResults & ";subtree"
  512.  
  513.         
  514.         Set rsADO = objADOCommand.Execute
  515.         If Err.Number then
  516.             WScript.Echo "Error 0x" & CStr(Hex(Err.Number)) & " occurred in executing ADO Query. "
  517.             If Err.Description <> "" Then WScript.Echo "Error description: " & Err.Description 
  518.             Err.Clear
  519.                     Exit Sub
  520.         End If
  521.  
  522.         
  523.         iCount = 0
  524.         If rsADO.RecordCount > 0 Then
  525.  
  526.             While Not rsADO.EOF
  527.  
  528.                 If blnQuiet Then WScript.Echo rsADO.Fields(1).Value & " found"
  529.                 If blnQuiet Then WScript.Echo "Attribute OID: " & objSrcClass.attributeID
  530.  
  531.                 If StrComp(objSrcClass.attributeID,rsADO.Fields(2).Value) <> 0 Then    
  532.                     WScript.Echo "Dst OID: " & rsADO.Fields(2).Value
  533.                     blnMatch=False
  534.                     If isObject(objFile) Then objFile.WriteLine "Dst OID: " & rsADO.Fields(2).Value
  535.                 Else
  536.                     If blnQuiet Then WScript.Echo "Src and Dst OID match"
  537.                 End If
  538.  
  539.                 if StrComp(objSrcClass.attributeSyntax ,rsADO.Fields(3).Value) <> 0 Then    
  540.                     WScript.Echo "Dst syntax: " & sADO.Fields(3).Value
  541.                     blnMatch=False
  542.                     If isObject(objFile) Then objFile.WriteLine "Dst syntax: " & sADO.Fields(3).Value
  543.                 Else
  544.                     If blnQuiet Then WScript.Echo "Attribute Syntax OK"
  545.                 End If
  546.  
  547.                 if objSrcClass.rangeLower <> rsADO.Fields(4).Value Then    
  548.                     WScript.Echo "Dst Range Lower " & rsADO.Fields(4).Value
  549.                     blnMatch=False
  550.                     If isObject(objFile) Then objFile.WriteLine "Dst Range Lower " & rsADO.Fields(4).Value
  551.                 Else
  552.                     If blnQuiet Then WScript.Echo "Range Lower OK"
  553.                 End If
  554.                 
  555.                 if objSrcClass.rangeUpper <> rsADO.Fields(5).Value Then    
  556.                     WScript.Echo "Dst Range Upper " & rsADO.Fields(5).Value
  557.                     blnMatch=False
  558.                     If isObject(objFile) Then objFile.WriteLine "Dst Range Upper " & rsADO.Fields(5).Value
  559.                 Else
  560.                     If blnQuiet Then WScript.Echo "Range Upper OK"
  561.                 End If
  562.  
  563.  
  564.                 rsADO.MoveNext
  565.             Wend
  566.         
  567.             
  568.                     
  569.         Else
  570.             WScript.Echo "Missing Attribute " & objSrcClass.ldapDisplayName
  571.             blnMatch=False
  572.             If isObject(objFile) Then objFile.WriteLine "Missing Attribute " & objSrcClass.ldapDisplayName
  573.  
  574.         End If
  575.     Next
  576.  
  577.     If blnMatch Then 
  578.                            WScript.Echo "** Schema is OK"
  579.         If isObject(objFile) Then objFile.WriteLine "** Schema is OK"
  580.     Else
  581.         WScript.Echo "** Schema Mismatch"
  582.         If isObject(objFile) Then objFile.WriteLine "** Schema Mismatch"
  583.     End If
  584.  
  585.     If isObject(objFile) Then objFile.Close
  586.     
  587. End Sub
  588.  
  589.  
  590. '********************************************************************
  591. '* Function    Compare2Arrays()
  592. '* Input        SrcArray
  593. '*        DstArray
  594. '* Output        If DstArray contains all the same elements as SrcArray Compare2Arrays 
  595. '*        returns CONST_PROCEED else returns CONST_STRING_NOT_FOUND
  596. '*
  597. '********************************************************************
  598. Function Compare2Arrays(SrcArray, DstArray)
  599. ON ERROR RESUME NEXT
  600.  
  601. Dim i, j, k, bFound
  602.  
  603. Compare2Arrays = CONST_STRING_NOT_FOUND
  604.  
  605.  
  606. If IsEmpty(SrcArray) And IsEmpty(DstArray) Then 
  607.     Compare2Arrays = CONST_PROCEED
  608.     Exit Function    
  609. End If
  610.  
  611.  
  612. If IsEmpty(SrcArray) And IsNull(DstArray) Then 
  613.     Compare2Arrays = CONST_PROCEED
  614.     Exit Function    
  615. End If
  616.  
  617.  
  618. If IsNull(SrcArray) And IsNull(DstArray) Then 
  619.     Compare2Arrays = CONST_PROCEED
  620.     Exit Function    
  621. End If
  622.  
  623.  
  624. If IsNull(SrcArray) And IsEmpty(DstArray) Then 
  625.     Compare2Arrays = CONST_PROCEED
  626.     Exit Function    
  627. End If
  628.  
  629.  
  630. If (Not IsArray(SrcArray)) And (Not IsArray(DstArray)) Then
  631.     If StrComp(SrcArray, DstArray) = 0 Then Compare2Arrays = CONST_PROCEED
  632.     Exit Function
  633. End If
  634.  
  635. If (Not IsArray(SrcArray)) And (IsArray(DstArray)) Then
  636.     If StrComp(SrcArray, DstArray(UBound(DstArray))) = 0 Then     Compare2Arrays = CONST_PROCEED
  637.     Exit Function
  638. End If
  639.  
  640. If (IsArray(SrcArray)) And (Not IsArray(DstArray)) Then
  641.     If StrComp(DstArray, SrcArray(UBound(SrcArray))) = 0 Then     Compare2Arrays = CONST_PROCEED
  642.     Exit Function
  643. End If
  644.  
  645. If UBound(SrcArray) <> UBound(DstArray) Then 
  646.     Exit Function
  647. End If
  648.  
  649. For i = LBound(SrcArray) to UBound(SrcArray)
  650.     bFound=False
  651.     For j = LBound(DstArray) to UBound(DstArray)
  652.         If StrComp(LCase(SrcArray(i)) ,LCase(DstArray(j))) = 0  Then bFound = True
  653.     Next
  654.     if bFound = False Then Exit Function
  655. Next
  656.  
  657. Compare2Arrays = CONST_PROCEED
  658.  
  659. End Function
  660.  
  661.  
  662.  
  663. '********************************************************************
  664. '*
  665. '* Function intSearchArray()
  666. '* Purpose: Searches an array for a given string.
  667. '* Input:   strTarget    the string to look for
  668. '*          strArray    an array of strings to search against
  669. '* Output:  If a match is found intSearchArray is set to the index of the element,
  670. '*          otherwise it is set to CONST_STRING_NOT_FOUND.
  671. '*
  672. '********************************************************************
  673.  
  674. Function intSearchArray(ByVal strTarget, ByVal strArray)
  675.  
  676. ON ERROR RESUME NEXT
  677.  
  678.     Dim i, j
  679.  
  680.     intSearchArray = CONST_STRING_NOT_FOUND
  681.  
  682.     If Not IsArray(strArray) Then
  683.         WScript.Echo "Argument is not an array!"
  684.         Exit Function
  685.     End If
  686.  
  687.     strTarget = LCase(strTarget)
  688.     For i = 0 To UBound(strArray)
  689.         j = InStr(1, strArray(i), strTarget, 1)
  690.         If j > 0 Then 
  691.            intSearchArray = i
  692.         End If
  693.     Next
  694. End Function
  695.  
  696. '********************************************************************
  697. '*
  698. '* Sub Print()
  699. '* Purpose:   Prints a message on screen If blnQuiet = False.
  700. '* Input:     strMessage    the string to print
  701. '* Output:    strMessage is printed on screen If blnQuiet = False.
  702. '*
  703. '********************************************************************
  704.  
  705. Sub Print(ByRef strMessage)
  706.     If Not blnQuiet then
  707.         Wscript.Echo  strMessage
  708.     End If
  709. End Sub
  710.  
  711. '********************************************************************
  712. '*
  713. '* Funcion sprintf()
  714. '* Purpose:   formats a string simlar to C runtime sprintf function
  715. '* Input:     VarArg    variable length array of strings
  716. '* Output:    formatted string
  717. '*
  718. '********************************************************************
  719. Public Function sprintf(VarArg())
  720. Dim iIndex
  721. Dim iArg
  722. Dim iCountArgs
  723. Dim sTemp
  724. Dim cChar
  725. Dim cNextChar
  726. Dim bFound
  727. Dim sVal
  728.  
  729. iArg = 1
  730. iCountArgs = UBound(VarArg) + 1
  731.  
  732. For iIndex = 1 to Len(VarArg(0))
  733.   cChar = Mid(VarArg(0),iIndex,1)
  734.   Select Case cChar
  735.   Case "%"
  736.     bFound = False
  737.     sVal = 0
  738.     Do While bFound=False
  739.       cNextChar=Mid(VarArg(0),iIndex+1,1)
  740.       iIndex=iIndex+1
  741.         Select Case cNextChar
  742.         Case "d","s"
  743.             bFound=True
  744.         Case Else
  745.             If sVal > 0 Then sVal = sVal * 10
  746.             sVal = sVal + cNextChar
  747.         End Select
  748.       Loop
  749.       If iArg < iCountArgs Then
  750.         If Len(VarArg(iArg)) > sVal Then 
  751.            sTemp = sTemp & Left(VarArg(iArg),sVal)
  752.         Else
  753.            sTemp = sTemp & VarArg(iArg) & Space(sVal-Len(VarArg(iArg))) 
  754.         End If 
  755.       End If
  756.       iArg = iArg +1
  757.   Case Else
  758.   sTemp = sTemp & cChar
  759.   End Select
  760. Next
  761. sprintf = sTemp
  762. End Function
  763.  
  764.  
  765. '********************************************************************
  766. '*                                                                  *
  767. '*                           End of File                      *
  768. '*                                                                  *
  769. '********************************************************************