Tuesday, April 19, 2016

PowerShell: Join Domain Users to Any Specific OU

I have been looking for ways for automatic domain join so that the end-users can do by themselves without special  knowledge. There are serveral scripts I found on google that make it work, but none of them seems to be an all-in-one solution.Moreover, I don't want to do usernames/password put in text files that are delivered to each user. So, I decided to make a complete script for automatic-domain-join  of users.

What this script will do:
1) Test the DNS Server is reacheable and if OK, change the users' DNS setting to point to Domain Controller.
2) Prompt for username/password to join to domain, no need to put username/pass with the script file.
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 one I liked most & the reason why I wrote this script xP ).

Things you need to do:
1) Modify the Admin section of the script to your needs

2) Delegate All OUs to create computer objects for domain users so that they themselves can join to the domain. (This is the one that took my most time troubleshooting the access denied error.)
I would recommend to create the new security group, delegate the permission to that group and put the domain users into the group. Because it's more safer to delete (rather than revoke delegation permission) that security group after all users are joined to domain.

3) Some Clients may need to enable powershell script execution policy to remotesigned, so that powershell scripts can execute. You can do it by another batch script that call the powershell script ,,, etc... etc..


1) Delegating OU Permission
Only the the Admin and Account Operator roles have permissions to create computer & users objects in any OU. We need some little right for users to perform themselves. But granting Account Operator roles to every domain users is a the one we should never do. So, I will give only necessary permissions.

Step1:
From Active Directory Users and Computers, Choose the parent OU you want to delegate.


Figure 1: Delegating the rootOU to "Domain Joiner" so that the users can themselves choose the correct ones.

Step2:
Delegate the security group to create computer objects in Active Directory.




Figure 2: Granting Domain Joiner Security Group for OU Delegation


Step3:
On the next page, choose Create a custom task to delegate.

Step4:
Choose Computer Objects and check the "Create selected objects in this folder" as shown in Fig-3.




 
Figure 3: Selecting the object types



Step 5:
Customize the permission Here I select the Write and Create all child objects. Others default.

Figure 4: Customizing Permissions



So far, we finished about delegating permission. Now, it's for the script section.


The Following is when I run on my computer.

1 comment:

  1. Nice Blog, Best microsoft office 2010 professional for Mac Home and Business edition is a powerful suite which fulfils the productivity applications, written for Mac OS X.

    ReplyDelete

Note: Only a member of this blog may post a comment.