{"id":68343,"date":"2005-12-13T13:24:00","date_gmt":"2005-12-13T13:24:00","guid":{"rendered":"https:\/\/blogs.technet.microsoft.com\/heyscriptingguy\/2005\/12\/13\/how-can-i-disable-a-computer-account\/"},"modified":"2005-12-13T13:24:00","modified_gmt":"2005-12-13T13:24:00","slug":"how-can-i-disable-a-computer-account","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/scripting\/how-can-i-disable-a-computer-account\/","title":{"rendered":"How Can I Disable a Computer Account?"},"content":{"rendered":"<p><IMG class=\"nearGraphic\" title=\"Hey, Scripting Guy! Question\" border=\"0\" alt=\"Hey, Scripting Guy! Question\" align=\"left\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/q-for-powertip.jpg\" width=\"34\" height=\"34\"> \n<P>Hey, Scripting Guy! How can I disable a computer account?<BR><BR>&#8212; MD<\/P><IMG border=\"0\" alt=\"Spacer\" src=\"https:\/\/devblogs.microsoft.com\/scripting\/wp-content\/uploads\/sites\/29\/2019\/05\/spacer.gif\" width=\"5\" height=\"5\"><IMG class=\"nearGraphic\" title=\"Hey, Scripting Guy! Answer\" border=\"0\" alt=\"Hey, Scripting Guy! Answer\" align=\"left\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/a-for-powertip.jpg\" width=\"34\" height=\"34\"><A href=\"http:\/\/go.microsoft.com\/fwlink\/?linkid=68779&amp;clcid=0x409\"><IMG class=\"farGraphic\" title=\"Script Center\" border=\"0\" alt=\"Script Center\" align=\"right\" src=\"http:\/\/img.microsoft.com\/library\/media\/1033\/technet\/images\/scriptcenter\/ad.jpg\" width=\"120\" height=\"288\"><\/A> \n<P>Hey, MD. You know, our first thought when we read your question was to ask our very own Peter Costantini, a scripting guru who\u2019s done a lot of work with Active Directory. For better or worse, however, Peter\u2019s originally from New Jersey and is a big fan of <I>The Sopranos<\/I>. Consequently, when we asked him how to disable a computer account he told us, \u201cWell, foist youse takes a baseball bat and cracks \u2018em good about the kneecaps \u2026.\u201d<\/P>\n<P>You know, come to think of it, that\u2019s Peter\u2019s solution to <I>every<\/I> question we pose to him. <\/P>\n<P>Admittedly, there have been plenty of times when we\u2019ve wanted to take a baseball bat to our computer; however, we weren\u2019t exactly sure how to find the computer\u2019s kneecaps. Therefore, we decided to disable a computer account using a script like this instead:<\/P><PRE class=\"codeSample\">Set objComputer = GetObject(&#8220;LDAP:\/\/cn=atl-ws-01,cn=computers,dc=fabrikam,dc=com&#8221;)<\/p>\n<p>objComputer.AccountDisabled = True\nobjComputer.SetInfo\n<\/PRE>\n<P>Maybe not as satisfying as whacking your computer with a baseball bat, but quicker, easier, and a lot cheaper to boot. We begin by binding to the computer account we want to disable; in this case that\u2019s a computer named atl-ws-01, which is located in the Computers container in fabrikam.com:<\/P><PRE class=\"codeSample\">Set objComputer = GetObject(&#8220;LDAP:\/\/cn=atl-ws-01,cn=computers,dc=fabrikam,dc=com&#8221;)\n<\/PRE>\n<P>Notice the syntax we used: <B>cn=computers<\/B>. It\u2019s important to remember that <B>Users<\/B> and <B>Computers<\/B> are <I>not<\/I> organizational units; that means the syntax ou=Computers will fail. Consequently, we use the <B>cn=<\/B> syntax instead. If our computer <I>was<\/I> in an OU (say, the Finance OU) then we\u2019d use the <B>ou=<\/B> syntax, like so:<\/P><PRE class=\"codeSample\">Set objComputer = GetObject(&#8220;LDAP:\/\/cn=atl-ws-01,ou=finance,dc=fabrikam,dc=com&#8221;)\n<\/PRE>\n<P>After making the connection all we do is set the <B>AccountDisabled<\/B> attribute to True. (Quick quiz: How could we enable a disabled account? That\u2019 right: set AccountDisabled to False.) We then call the <B>SetInfo<\/B> method to write the changes back to Active Directory and we\u2019re done.<\/P>\n<TABLE id=\"ELE\" class=\"dataTable\" cellSpacing=\"0\" cellPadding=\"0\">\n<THEAD><\/THEAD>\n<TBODY>\n<TR class=\"record\" vAlign=\"top\">\n<TD>\n<P class=\"lastInCell\"><B>Important clarification<\/B>. Peter has pointed out that he doesn\u2019t actually say things like \u201cfoist\u201d and \u201cyouse,\u201d and said he is tired of people from Washington state making fun of people from New Jersey. With that in mind, he politely asked us to apologize for our disrespect; otherwise, he\u2019d take a baseball bat to <I>our<\/I> kneecaps. Peter, we apologize.<\/P><\/TD><\/TR><\/TBODY><\/TABLE><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Hey, Scripting Guy! How can I disable a computer account?&#8212; MD Hey, MD. You know, our first thought when we read your question was to ask our very own Peter Costantini, a scripting guru who\u2019s done a lot of work with Active Directory. For better or worse, however, Peter\u2019s originally from New Jersey and is [&hellip;]<\/p>\n","protected":false},"author":595,"featured_media":87096,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[1],"tags":[7,46,3,5],"class_list":["post-68343","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-scripting","tag-active-directory","tag-computer-accounts","tag-scripting-guy","tag-vbscript"],"acf":[],"blog_post_summary":"<p>Hey, Scripting Guy! How can I disable a computer account?&#8212; MD Hey, MD. You know, our first thought when we read your question was to ask our very own Peter Costantini, a scripting guru who\u2019s done a lot of work with Active Directory. For better or worse, however, Peter\u2019s originally from New Jersey and is [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/posts\/68343","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/users\/595"}],"replies":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/comments?post=68343"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/posts\/68343\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/media\/87096"}],"wp:attachment":[{"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/media?parent=68343"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/categories?post=68343"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/tags?post=68343"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}