Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

136 lines
4.0 KiB

  1. ' clonedom.vbi start
  2. // VB Script "Include" file for CloneSecurityPrincipal scripts
  3. //
  4. // contains code common to all the scripts
  5. //
  6. // Copyright (c) 1999 Microsoft Corporation.
  7. const ARG_COUNT = 5
  8. sub Main
  9. if wscript.arguments.count <> ARG_COUNT then
  10. PrintUsageAndQuit
  11. end if
  12. ' copy the command-line arguments for parsing
  13. dim args()
  14. Redim args(0)
  15. args(0) = ""
  16. dim i
  17. for i = 0 to wscript.arguments.count - 1
  18. Redim Preserve args(i)
  19. args(i) = wscript.arguments.item(i)
  20. next
  21. ' command line parameters
  22. dim srcDC ' source domain controller
  23. dim srcDom ' source domain
  24. dim dstDC ' destination controller
  25. dim dstDom ' destination domain
  26. dim dstOU ' destination OU for clones
  27. ' parse the saved command-line arguments, extracting the values
  28. srcDC = GetArgValue("srcdc", args)
  29. srcDom = GetArgValue("srcdom", args)
  30. dstDC = GetArgValue("dstdc", args)
  31. dstDom = GetArgValue("dstdom", args)
  32. dstOU = GetArgValue("dstou", args)
  33. ' ensure the user did not pass any unrecognized command-line arguments
  34. if CheckForBadArgs(args) then
  35. Echo "Unknown command-line arguments specified"
  36. PrintUsageAndQuit
  37. end if
  38. ' establish authenticate connections to the source and destination domain
  39. ' controllers
  40. on error resume next
  41. clonepr.Connect srcDC, srcDom, dstDC, dstDom
  42. if Err.Number then DumpErrAndQuit
  43. Echo "Connected to source and destination domain controllers"
  44. dim srcDomain
  45. set srcDomain = GetObject("WinNT://" & srcDom & "/" & srcDC & ",Computer")
  46. if Err.Number then DumpErrAndQuit
  47. ' for every security principal in the source domain, call
  48. ' ShouldCloneObject. if that function returns True, then clone the object.
  49. ' Otherwise ignore it.
  50. dim cloneCounter
  51. dim srcObject
  52. dim srcObjectClass
  53. cloneCounter = 0
  54. for each srcObject in srcDomain
  55. if ShouldCloneObject(srcObject) then
  56. Echo "Bound to source " & srcObject.Class & " " & srcObject.Name
  57. srcObjectClass = ObjectClass(srcObject)
  58. do
  59. if srcObjectClass = CLASS_USER then
  60. if srcObject.UserFlags and UF_TEMP_DUPLICATE_ACCOUNT then
  61. Echo "Skipping temporary local user account."
  62. exit do
  63. end if
  64. end if
  65. dim srcSam ' source principal SAM name
  66. dim dstSam ' destination principal SAM name
  67. dim dstDN ' destination principal full DN
  68. srcSam = srcObject.Name
  69. dstSam = srcSam
  70. dstDN = adsPathname.GetEscapedElement(0, "CN=" & dstSam) & "," & dstOU
  71. CloneSecurityPrincipal srcObject, srcSam, dstDom, dstDC, dstSam, dstDN
  72. cloneCounter = cloneCounter + 1
  73. loop while 0
  74. Echo ""
  75. end if
  76. next
  77. Echo cloneCounter & " objects(s) cloned"
  78. end sub
  79. sub PrintUsageAndQuit
  80. Echo "Usage: cscript " & SCRIPT_FILENAME & " /srcdc:<dcname> /srcdom:<domain>"
  81. Echo "/dstdc:<dcname> /dstdom:<domain> /dstou:<ouname>"
  82. Echo ""
  83. Echo "Parameters:"
  84. Echo " /srcdc - source domain controller NetBIOS computer name (without leading \\)"
  85. Echo ""
  86. Echo " /srcdom - source domain NetBIOS name"
  87. Echo ""
  88. Echo " /dstdc - destination domain controller NetBIOS computer name (without "
  89. Echo " leading \\)"
  90. Echo " This script must be run on the machine indicated here."
  91. Echo ""
  92. Echo " /dstdom - destination domain DNS name"
  93. Echo ""
  94. Echo " /dstou - destination OU for the clones"
  95. Echo ""
  96. Echo "Notes:"
  97. Echo ""
  98. Echo "If the destination principals do not exist, they will be created."
  99. Echo "In that case, the OU named by dstou must exist."
  100. Echo ""
  101. Echo "Currently logged-on user must be a member of the Administrators"
  102. Echo "group of both the source and destination domains."
  103. Echo ""
  104. Echo SCRIPT_DATE & " " & SCRIPT_TIME
  105. wscript.quit(0)
  106. end sub
  107. ' clonedom.vbi end