Domain Join Powershell Script
Add computer domainname domain01 server domain01 dc01 passthru verbose.
Domain join powershell script. To run this script open powershell ise with an administrator account on the computer being renamed and joined to the domain and edit the following variables. When you run the script you will see the command prompt as shown below. The add computer cmdlet used to add the local or remote computer to a domain.
It then retrieves the wmi computersystem object and uses the joindomainorworkgroup method to join. The command uses the passthru and verbose parameters to get detailed information about the results of the command. That s why creating a custom powershell script to join your domain will be customize to only your environment so the security risk is very low.
Join a computer to a domain this script mimics the basic functionality of the add computer cmdlet with reduced functionality. Using powershell scripts within a task sequence provides more flexibility than using the customsettings ini file to join a computer to a domain. This command adds the local computer to the domain01 domain by using the domain01 dc01 domain controller.
The powershell command requires the distinguished name. The parameters of the customsettings ini file are common to any deployment you perform. Put the computer account into the specified domain organizational unit ou.
Add computer domainname domain02 oupath ou testou dc domain dc domain dc com in the following example i ll be adding computers to the domain that go to the sales department. The following script is using an administrator account to join the domain and before it joins the domain it asks for the password of the administrator. Save the script is ps1 and run it from the machine.
It also can be used to add to a workgroup or to move it from one domain to another. Thankfully we can automate this with powershell when we join the computers to the domain. For the newhostname variable specify the new name for the computer.