Ragnarok Posted July 29, 2015 Share Posted July 29, 2015 (edited) Hi - and many thanks in advance for those who may have the answer (or can point me in the right direction)!I'm working on a script to Unjoin a Windows 7 x64 PC from its domain (using version 3.3.12.0) - there are two possible domains here, and I'd like the script to work for both, for ease of use.The _AD_Open command works beautifully, but I always get the same return code from _AD_UnjoinDomain: "Return code '0' from Active Directory" This makes things kinda hard to track down.I'm not sure what I'm doing wrong here - I've tried changing the workgroup name, omitting the workgroup, etc. I've hardcoded the user/password into the script for both domains, as they have rights to add / remove machines. I've also tried the username in both [DOMAIN][USER] and [USER] formats.expandcollapse popup#Include <AD.au3> #RequireAdmin ;==============[ SET VARIABLES ]============== ; [Removed for Reasons. ;============[ END SET VARIABLES ]============ ; Get current domain $ComputerDomain = StringUpper(_DomainComputerBelongs()) ; Name temporary workgroup $strWorkgroup = "DOM_TRANSFER" ; Open connection to the domain _Open_Domain() ; Leave the domain _Leave_Domain() ;==============[ Open Active Directory Connection ]============== Func _Open_Domain() ; Open Connection to Active Directory If $ComputerDomain = "[DOMAIN1].COM" Then $iValue = _AD_Open($strProdUser, $strProdPassword, $prodDNSDomainParam, $ComputerDomain, $prodConfigParam) ElseIf $ComputerDomain = "[DOMAIN2].COM" Then $iValue = _AD_Open($strSandUser, $strSandPassword, $sandDNSDomainParam, $ComputerDomain, $sandConfigParam) EndIf ;MsgBox(0,"_AD_Open",$iValue) If @error Then Exit MsgBox(16, "Leave Domain", "Function _AD_Open encountered a problem. @error = " & @error & ", @extended = " & @extended) Global $iReply = MsgBox(308, "Leave Domain", "Are you sure you want to leave the " & $ComputerDomain & " domain?") If $iReply <> 6 Then Exit EndFunc ;==============[ Leave Current Domain ]============== Func _Leave_Domain() If $ComputerDomain = "[DOMAIN1].COM" Then ; Leave [DOMAIN1].COM Global $iValue = _AD_UnJoinDomain(@ComputerName, $strWorkgroup, $strProdUser ,$strProdPassword) _Translate_UnjoinMessage() ElseIf $ComputerDomain = "[DOMAIN2].COM" Then ; Leave [DOMAIN2].COM Global $iValue = _AD_UnJoinDomain(@ComputerName, $strWorkgroup, $strSandUser ,$strSandPassword) _Translate_UnjoinMessage() Else MsgBox(0,"Information","No domain to unjoin.") EndIf ; Close Connection to Active Directory _AD_Close() EndFunc Edited July 29, 2015 by Ragnarok Runaway bracket removed. :) Link to comment Share on other sites More sharing options...
Ragnarok Posted July 29, 2015 Author Share Posted July 29, 2015 Solved my issue - I'd forgotten to remove the domain from the username variable. Oops. Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now