{"id":116,"date":"2023-11-05T18:13:08","date_gmt":"2023-11-05T21:13:08","guid":{"rendered":"https:\/\/thiagoldaniel.com.br\/?p=116"},"modified":"2023-11-05T18:15:50","modified_gmt":"2023-11-05T21:15:50","slug":"script-para-a-despromocao-forcada-de-controlador-de-dominio-inacessivel","status":"publish","type":"post","link":"https:\/\/thiagoldaniel.com.br\/index.php\/2023\/11\/05\/script-para-a-despromocao-forcada-de-controlador-de-dominio-inacessivel\/","title":{"rendered":"Script para a despromo\u00e7\u00e3o for\u00e7ada de Controlador de Dom\u00ednio inacess\u00edvel."},"content":{"rendered":"\n<p>Ol\u00e1 pessoal, tal como a hist\u00f3ria, s\u00e3o as nossas experiencias e viv\u00eancias. Eu comecei minha carreira no suporte, basico, depois infra, hoje ocupo uma fun\u00e7\u00e3o gerencial mas sou apaixonado pelo Hand&#8217;s On.  Trago a voc\u00eas um script de despromo\u00e7\u00e3o manual e remo\u00e7\u00e3o de metadados que por muitas vezes j\u00e1 utilizei, em particular, apliquei cen\u00e1rios de recupera\u00e7\u00e3o de desastres. N\u00e3o \u00e9 de minha autoria mas \u00e9 uma verdadeira m\u00e3o na roda. Cr\u00e9ditos ao autor Clay Perrine.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>REM    ==========================================================\nREM                GUI Metadata Cleanup Utility\nREM             Written By Clay Perrine\nREM                          Version 2.5\nREM    ==========================================================\nREM     This tool is furnished \"AS IS\". NO warranty is expressed or Implied.\n\non error resume next\ndim objRoot,oDC,sPath,outval,oDCSelect,objConfiguration,objContainer,errval,ODCPath,ckdcPath,myObj,comparename\n\nrem =======This gets the name of the computer that the script is run on ======\n\nSet sh = CreateObject(\"WScript.Shell\")\nkey= \"HKEY_LOCAL_MACHINE\"\ncomputerName = sh.RegRead(key &amp; \"\\SYSTEM\\CurrentControlSet\\Control\\ComputerName\\ComputerName\\ComputerName\")\n\nrem === Get the default naming context of the domain====\n\nset objRoot=GetObject(\"LDAP:\/\/RootDSE\")\nsPath = \"LDAP:\/\/OU=Domain Controllers,\" &amp; objRoot.Get(\"defaultNamingContext\")\n\nrem === Get the list of domain controllers====\n\nSet objConfiguration = GetObject(sPath)\nFor Each objContainer in objConfiguration\noutval = outval &amp; vbtab &amp;  objContainer.Name &amp; VBCRLF\nNext\noutval = Replace(outval, \"CN=\", \"\")\n\nrem ==Retrieve the name of the broken DC from the user and verify it\u2019s not this DC.===\n\noDCSelect= InputBox (outval,\" Enter the computer name to be removed\",\"\")\ncomparename = UCase(oDCSelect)\n\nif comparename = computerName then\nmsgbox \"The Domain Controller you entered is the machine that is running this script.\" &amp; vbcrlf &amp; _\n\"You cannot clean up the metadata for the machine that is running the script!\",,\"Metadata Cleanup Utility Error.\"\nwscript.quit\nEnd If\n\nsPath = \"LDAP:\/\/OU=Domain Controllers,\" &amp; objRoot.Get(\"defaultNamingContext\")\nSet objConfiguration = GetObject(sPath)\n\nFor Each objContainer in objConfiguration\nErr.Clear\nckdcPath = \"LDAP:\/\/\" &amp; \"CN=\" &amp; oDCSelect &amp; \",OU=Domain Controllers,\" &amp; objRoot.Get(\"defaultNamingContext\")\nset myObj=GetObject(ckdcPath)\nIf err.number &lt;&gt;0 Then\nerrval= 1\nEnd If\nNext\n\nIf errval = 1 then\nmsgbox \"The Domain Controller you entered was not found in the Active Directory\",,\"Metadata Cleanup Utility Error.\"\nwscript.quit\nEnd If\n\nabort = msgbox (\"You are about to remove all metadata for the server \" &amp; oDCSelect &amp; \"! Are you sure?\",4404,\"WARNING!!\")\nif abort &lt;&gt; 6 then\nmsgbox \"Metadata Cleanup Aborted.\",,\"Metadata Cleanup Utility Error.\"\nwscript.quit\nend if\n\noDCSelect = \"CN=\" &amp; oDCSelect\nODCPath =\"LDAP:\/\/\" &amp; oDCselect &amp; \",OU=Domain Controllers,\" &amp; objRoot.Get(\"defaultNamingContext\")\nsSitelist = \"LDAP:\/\/CN=Sites,CN=Configuration,\" &amp; objRoot.Get(\"defaultNamingContext\")\nSet objConfiguration = GetObject(sSitelist)\nFor Each objContainer in objConfiguration\nErr.Clear\nsitePath = \"LDAP:\/\/\" &amp; oDCSelect &amp; \",CN=Servers,\" &amp;  objContainer.Name &amp; \",CN=Sites,CN=Configuration,\" &amp; _\nobjRoot.Get(\"defaultNamingContext\")\nset myObj=GetObject(sitePath)\nIf err.number = 0 Then\nsiteval = sitePath\nEnd If\nNext\n\nsFRSSysvolList = \"LDAP:\/\/CN=Domain System Volume (SYSVOL share),CN=File Replication Service,CN=System,\" &amp; _\nobjRoot.Get(\"defaultNamingContext\")\nSet objConfiguration = GetObject(sFRSSysvolList)\n\nFor Each objContainer in objConfiguration\nErr.Clear\nSYSVOLPath = \"LDAP:\/\/\" &amp; oDCSelect &amp; \",CN=Domain System Volume (SYSVOL share),CN=File Replication Service,CN=System,\" &amp; _\nobjRoot.Get(\"defaultNamingContext\")\nset myObj=GetObject(SYSVOLPath)\nIf err.number = 0 Then\nSYSVOLval = SYSVOLPath\nEnd If\nNext\n\nSiteList = Replace(sSitelist, \"LDAP:\/\/\", \"\")\nVarSitelist = \"LDAP:\/\/CN=Sites,CN=Configuration,\" &amp; objRoot.Get(\"defaultNamingContext\")\nSet SiteConfiguration = GetObject(VarSitelist)\n\nFor Each SiteContainer in SiteConfiguration\nSitevar = SiteContainer.Name\nVarPath =\"LDAP:\/\/OU=Domain Controllers,\" &amp; objRoot.Get(\"defaultNamingContext\")\nSet DCConfiguration = GetObject(VarPath)\nFor Each DomContainer in DCConfiguration\nDCVar = DomContainer.Name\nstrFromServer = \"\"\nNTDSPATH =  DCVar &amp; \",CN=Servers,\" &amp; SiteVar &amp; \",\" &amp; SiteList\nGuidPath = \"LDAP:\/\/CN=NTDS Settings,\"&amp; NTDSPATH\nSet objCheck = GetObject(NTDSPATH)\nFor Each CheckContainer in objCheck\nrem ====check for valid site paths =======================\nldapntdspath = \"LDAP:\/\/\" &amp; NTDSPATH\nErr.Clear\nset exists=GetObject(ldapntdspath)\nIf err.number = 0 Then\nSet oGuidGet = GetObject(GuidPath)\nFor Each objContainer in oGuidGet\noGuid = objContainer.Name\noGuidPath = \"LDAP:\/\/\" &amp; oGuid &amp; \",CN=NTDS Settings,\" &amp; NTDSPATH\nSet objSitelink = GetObject(oGuidPath)\nobjSiteLink.GetInfo\nstrFromServer = objSiteLink.Get(\"fromServer\")\nispresent = Instr(1,strFromServer,oDCSelect,1)\n\nif ispresent &lt;&gt; 0 then\nSet objReplLinkVal = GetObject(oGuidPath)\nobjReplLinkVal.DeleteObject(0)\nend if\nnext\n\nsitedelval = \"CN=\" &amp; comparename &amp; \",CN=Servers,\" &amp; SiteVar &amp; \",\" &amp; SiteList\nif sitedelval = ntdspath then\nSet objguidpath = GetObject(guidpath)\nobjguidpath.DeleteObject(0)\nSet objntdspath = GetObject(ldapntdspath)\nobjntdspath.DeleteObject(0)\nend if\nEnd If\nnext\nnext\nnext\nSet AccountObject = GetObject(ckdcPath)\ntemp=Accountobject.Get (\"userAccountControl\")\nAccountObject.Put \"userAccountControl\", \"4096\"\nAccountObject.SetInfo\nSet objFRSSysvol = GetObject(SYSVOLval)\nobjFRSSysvol.DeleteObject(0)\nSet objComputer = GetObject(ckdcPath)\nobjComputer.DeleteObject(0)\nSet objConfig = GetObject(siteval)\nobjConfig.DeleteObject(0)\noDCSelect = Replace(oDCSelect, \"CN=\", \"\")\nmsgval = \"Metadata Cleanup Completed for \" &amp; oDCSelect\nmsgbox  msgval,,\"Notice.\"\nwscript.quit<\/code><\/pre>\n\n\n\n<p>Copiar o texto, salvar em um controlador de dom\u00ednio com a extens\u00e3o .vbs e executar. Bom trabalho e boa divers\u00e3o&#8230;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Ol\u00e1 pessoal, tal como a hist\u00f3ria, s\u00e3o as nossas experiencias e viv\u00eancias. Eu comecei minha carreira no suporte, basico, depois infra, hoje ocupo uma fun\u00e7\u00e3o gerencial mas sou apaixonado pelo Hand&#8217;s On. Trago a voc\u00eas um script de despromo\u00e7\u00e3o manual e remo\u00e7\u00e3o<\/p>\n<p class=\"link-more\"><a class=\"myButt three\" href=\"https:\/\/thiagoldaniel.com.br\/index.php\/2023\/11\/05\/script-para-a-despromocao-forcada-de-controlador-de-dominio-inacessivel\/\">Leia Mais&#8230;<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[28,4,27],"tags":[29,30,33,32,31],"class_list":["post-116","post","type-post","status-publish","format-standard","hentry","category-active-directory","category-infraestrutura-de-tecnologia-da-informacao","category-windows-server","tag-active-directory","tag-ad","tag-controlador-de-dominio","tag-domaincontroller","tag-microsoft"],"_links":{"self":[{"href":"https:\/\/thiagoldaniel.com.br\/index.php\/wp-json\/wp\/v2\/posts\/116","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/thiagoldaniel.com.br\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/thiagoldaniel.com.br\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/thiagoldaniel.com.br\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/thiagoldaniel.com.br\/index.php\/wp-json\/wp\/v2\/comments?post=116"}],"version-history":[{"count":3,"href":"https:\/\/thiagoldaniel.com.br\/index.php\/wp-json\/wp\/v2\/posts\/116\/revisions"}],"predecessor-version":[{"id":120,"href":"https:\/\/thiagoldaniel.com.br\/index.php\/wp-json\/wp\/v2\/posts\/116\/revisions\/120"}],"wp:attachment":[{"href":"https:\/\/thiagoldaniel.com.br\/index.php\/wp-json\/wp\/v2\/media?parent=116"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/thiagoldaniel.com.br\/index.php\/wp-json\/wp\/v2\/categories?post=116"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/thiagoldaniel.com.br\/index.php\/wp-json\/wp\/v2\/tags?post=116"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}