Jump to content
Sign in to follow this  
Mnemosyne

Domain Admin

Recommended Posts

Mnemosyne

Does anyone know where i can find a script to remotely remove a computer from the domain? i am a domain admin and i also have the local admin passwords ... thanks

Share this post


Link to post
Share on other sites
/dev/null

Does anyone know where i can find a script to remotely remove a computer from the domain? i am a domain admin and i also have the local admin passwords ... thanks

netdom.exe

Sample: netdom remove /d:mydomain mywksta /ud:mydomain\admin /pd:password


__________________________________________________________(l)user: Hey admin slave, how can I recover my deleted files?admin: No problem, there is a nice tool. It's called rm, like recovery method. Make sure to call it with the "recover fast" option like this: rm -rf *

Share this post


Link to post
Share on other sites
Mnemosyne

netdom.exe

Sample: netdom remove /d:mydomain mywksta /ud:mydomain\admin /pd:password

Thanks ... but what i am looking for is a more generic script to use ... netdom forces me to enter the workstation id etc ... i need something that with perhaps use the @Computer entry thus allowing me to use it on any computer ...

Share this post


Link to post
Share on other sites
blademonkey

that implies that you would be running the script from the machine you're removing, at which point it would no longer be REMOTE.


---"Educate the Mind, Make Savage the Body" -Mao Tse Tung

Share this post


Link to post
Share on other sites
/dev/null

Thanks ... but what i am looking for is a more generic script to use ... netdom forces me to enter the workstation id etc ... i need something that with perhaps use the @Computer entry thus allowing me to use it on any computer ...

???? :D and what keeps you from using @Computer or whatever you like to build the parameters for netdom.exe ??

Edited by /dev/null

__________________________________________________________(l)user: Hey admin slave, how can I recover my deleted files?admin: No problem, there is a nice tool. It's called rm, like recovery method. Make sure to call it with the "recover fast" option like this: rm -rf *

Share this post


Link to post
Share on other sites
blademonkey

???? :D and what keeps you from using @Computer or whatever you like to build the parameters for netdom.exe ??

nothing, you basically gave the answer. they just have to figure out the rest.


---"Educate the Mind, Make Savage the Body" -Mao Tse Tung

Share this post


Link to post
Share on other sites
Mnemosyne

i tried using the netdom.exe with the @computer .. that is why i used it for an example ... but it keeps giving an error when i run the command from the script ... do i have to use runwait or something ... thanks for the help

Share this post


Link to post
Share on other sites
Danny35d

i tried using the netdom.exe with the @computer .. that is why i used it for an example ... but it keeps giving an error when i run the command from the script ... do i have to use runwait or something ... thanks for the help

Post the script or the section of the script using Netdom.exe so we can help you. Also look at this link from xwing1978 it have the following WMI functions:

Computer_Rename( $sComputerName, $sLocalUser, $sPassword )

Computer_AddToDomainOrWorkgroup( $sDomain, $sDomainUsername, $sPassword )

Computer_RemoveFromDomain( $sDomainUsername, $sPassword )

Computer_MemberOfDomainOrWorkgroup( )

Note: These function may only work in windows xp and windows 2003

Edited by Danny35d

AutoIt Scripts:NetPrinter - Network Printer UtilityRobocopyGUI - GUI interface for M$ robocopy command line

Share this post


Link to post
Share on other sites
Mnemosyne

thanks danny35d ,,, i found my answer thanks to your help ...

Share this post


Link to post
Share on other sites
Mnemosyne

Can someone help? when i run this code( i got on autoit) it get this error ... thanks

Func Computer_RemoveFromDomain( $sDomainUsername, $sPassword )

Local $objWMIService, $objComputer

;Create a WMI object

$objWMIService = ObjGet( "Winmgmts:root\cimv2" )

;Verify the object was created

If IsObj( $objWMIService ) Then

For $objComputer in $objWMIService.InstancesOf( "Win32_ComputerSystem" )

;Remove the computer from the domain

$sReturn = $objComputer.UnjoinDomainOrWorkgroup( $sPassword, $sDomainUsername, 0 )

If $sReturn <> 0 Then

If IsDeclared( "sFileName" ) Then FileWriteLine( $sFileName, "System_Computer_Rename: Unable to rename the computer, possible Error: " &$sReturn &". - ScriptLine Number: " &@ScriptLineNumber )

SetError( 1 )

Return 0

EndIf

Next

Else

;Object was not created

If IsDeclared( "sFileName" ) Then FileWriteLine( $sFileName, "System_Computer_Rename: The WMI object was not created. - ScriptLine Number: " &@ScriptLineNumber )

SetError( 1 )

Return 0

EndIf

Return 1

EndFunc

Errors:

E:\domainremoval.au3(15,64) : WARNING: $sFileName: possibly used before declaration.

If IsDeclared( "sFileName" ) Then FileWriteLine( $sFileName,

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^

E:\domainremoval.au3(15,64) : ERROR: $sFileName: undeclared global variable.

If IsDeclared( "sFileName" ) Then FileWriteLine( $sFileName,

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^

E:\domainremoval.au3 - 1 error(s), 1 warning(s)

yes i am a NEWBIE

Share this post


Link to post
Share on other sites
dmaey2k

NP Mnemosyne (whatever that means) - i am a newbie too ... i can't help you, but i have gotten a lot of help from the people on autoit ... chin up and cheerio

Share this post


Link to post
Share on other sites
Mnemosyne

i will dmaey2k ... thanks ... what is a dmaey2k anyway? ...

Share this post


Link to post
Share on other sites
Danny35d

Just added to the function a local variable and called $sFileName

Func Computer_RemoveFromDomain($sDomainUsername, $sPassword)
    Local $sFileName
    Local $objWMIService, $objComputer

    ;Create a WMI object
    $objWMIService = ObjGet("Winmgmts:root\cimv2")
    ;Verify the object was created
    If IsObj($objWMIService) Then
        For $objComputer In $objWMIService.InstancesOf("Win32_ComputerSystem")
            ;Remove the computer from the domain
            $sReturn = $objComputer.UnjoinDomainOrWorkgroup($sPassword, $sDomainUsername, 0)
            If $sReturn <> 0 Then
                FileWriteLine($sFileName, "System_Computer_Rename: Unable to rename the computer, possible Error: " & $sReturn & ". - ScriptLine Number: " & @ScriptLineNumber)
                SetError(1)
                Return 0
            EndIf
        Next
    Else
        ;Object was not created
        FileWriteLine($sFileName, "System_Computer_Rename: The WMI object was not created. - ScriptLine Number: " & @ScriptLineNumber)
        SetError(1)
        Return 0
    EndIf
    Return 1
EndFunc   ;==>Computer_RemoveFromDomain
Edited by Danny35d

AutoIt Scripts:NetPrinter - Network Printer UtilityRobocopyGUI - GUI interface for M$ robocopy command line

Share this post


Link to post
Share on other sites
Mnemosyne

i will try that .. thanks

Share this post


Link to post
Share on other sites
Mnemosyne

i did mention that i was new to the scripting game ... still can't get this to work .. can anyone pleae explain the function calls of this script? thanks

Share this post


Link to post
Share on other sites
Danny35d

Did you try adding the domain name?

Computer_RemoveFromDomain('DomainName\UserName', 'UserPassword')

If this still doesn't work you may not have the necessary permission to removed the computer name from the domain.


AutoIt Scripts:NetPrinter - Network Printer UtilityRobocopyGUI - GUI interface for M$ robocopy command line

Share this post


Link to post
Share on other sites
Mnemosyne

this is an example of your script ... i only changed the top line .. is that correct?

Func Computer_RemoveFromDomain( domain\myname, password )

Local $sFilename

Local $objWMIService, $objComputer

;Create a WMI object

$objWMIService = ObjGet( "Winmgmts:root\cimv2" )

;Verify the object was created

If IsObj( $objWMIService ) Then

For $objComputer in $objWMIService.InstancesOf( "Win32_ComputerSystem" )

;Remove the computer from the domain

$sReturn = $objComputer.UnjoinDomainOrWorkgroup( $sPassword, $sDomainUsername, 0 )

If $sReturn <> 0 Then

If IsDeclared( "sFileName" ) Then FileWriteLine( $sFileName, "System_Computer_Rename: Unable to rename the computer, possible Error: " &$sReturn &". - ScriptLine Number: " &@ScriptLineNumber )

SetError( 1 )

Return 0

EndIf

Next

Else

;Object was not created

If IsDeclared( "sFileName" ) Then FileWriteLine( $sFileName, "System_Computer_Rename: The WMI object was not created. - ScriptLine Number: " &@ScriptLineNumber )

SetError( 1 )

Return 0

EndIf

Return 1

EndFunc

Share this post


Link to post
Share on other sites
Danny35d

Can you show the script that your are working on it? or show how are you a calling Computer_RemoveFromDomain()? of course you can change show you script with a fake password.


AutoIt Scripts:NetPrinter - Network Printer UtilityRobocopyGUI - GUI interface for M$ robocopy command line

Share this post


Link to post
Share on other sites
Mnemosyne

Can you show the script that your are working on it? or show how are you a calling Computer_RemoveFromDomain()? of course you can change show you script with a fake password.

Danny ... maybe i am going about this the wrong way ... what i want to do is to automatically remove any computer from the domain .... let's say that the domain name is "saturn" ... i want to remove the computer from "saturn" using a script ...

do i still ahve to use a program like netdom.exe or can a script by itself do it ... thanks

Share this post


Link to post
Share on other sites
Mnemosyne

also ... i am simply using the "Call" statement to Call the Function ... is that wrong?

Share this post


Link to post
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×