Domain Join To Specific Ou Using Powershell
Add computer domainname domain cred domain administrator passthru oupath ou xxx dc domain dc domain.
Domain join to specific ou using powershell. In other way. Best practice is to pre create the computer account in ad before joining to domain. You can use power shell cmdlet.
Function join domain param parameter position 0 string computername env computername parameter position 1 validateset ou computers ou chicago dc your dc domain dc here ou computers ou paris dc your dc domain dc here ou computers ou sydney dc your dc domain dc here ou computers ou toronto dc your dc domain dc here string ou cn computers ou chicago dc your dc domain dc here renamecomputer true if computername eq or. A powershell script to add a server to a specific ou when joining a domain. Thankfully we can automate this with powershell when we join the computers to the domain.
Things you need to do. Add computer domainname domain02 oupath ou testou dc domain dc domain dc com. Powershell gives you the ability to add computers to active directory right from the command line with the built in powershell commandlets.
Add computer computername server01 server02 localhost domainname domain02 localcredential domain01 user01 unjoindomaincredential domain01 admin01 credential domain02 admin01 restart. 3 users can choose their own ou for their domain join process so admin doesn t need to move thier computer objects to specific ou after domain join. The active directory domain join of a computer can be done using either the gui or using command line and powershell.
This command moves the server01 and server02 computers and the local computer from domain01 to domain02. In this tutorial i will explain how to join a computer to a domain using the various command lines that are. 2 prompt for username password to join to domain no need to put username pass with the script file.
Join computer to domain with specified computer name and ou. If the script fails it will generate an error. The script will prompt for a username and password before it joins.