Sign in to follow this  
Followers 0
Prodian

Simple Join Domain Script

1 post in this topic

I was looking for a simple join domain script and the ones I found were very complex and didn't do a simple join domain so heres one I came up with, it works great. Pretty self explanitory, you need to replace a couple variables such as server, domain, username, and password with your own.

;----------------------------------------------
;----------------------------------------------
;Automatically Adds Computer to Domain
;----------------------------------------------
;----------------------------------------------


$server = "\\serverIP\Share"

Run("net use Z: " & $server,"",@SW_HIDE);Maps a network drive to copy netdom.exe to system32 if needed

Sleep(2000)

$domain = "yourdomain.com"
$username = "username"
$password = "password"

If $ans = 6 Then
    
    If FileExists("C:\Windows\System32\netdom.exe") Then;Checks to see if netdom.exe is in system32
        
    Else
        Run("Z:\add_domain.bat");Runs a copy batch file to copy netdom.exe from a server to system32
    EndIf
    
    $cmd = "netdom.exe join " & @ComputerName & " /domain:" & $domain & " /userd:" & $username & " /passwordd:" & $password & " /reboot 5"
    
    $Return = RunWait(@ComSpec & " /C " & $cmd,'',@SW_HIDE)
    
    If $Return <> 0 Then
        MsgBox(48, "Error","Computer was not joined to the domain")
        Run("net use /delete Z:","",@SW_HIDE)
        Exit
    Else
        MsgBox(48, "Complete!",@ComputerName & " was successfully joined to the domain!")       
        
    ProcessWaitClose("netdom.exe")  
        
    Run("net use /delete Z:","",@SW_HIDE)       
        
    Exit
    
    EndIf

EndIf

If $ans = 7 Then
    
    MsgBox(48,"Change Name!","Please change the computer name before adding to the domain!")
    
    Run("net use /delete Z:","",@SW_HIDE)
    
    Exit
    
EndIf

Exit

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  
Followers 0