Script to Join Active Directory Domain with Local user Profile migration

Writing a long, quality script can be both a tiresome and interesting task in terms of its look and feel. It’s been quite a while since I last wrote a substantial script, as I’ve mostly been occupied with small utility scripts in my work. Today, I completed a very useful script that joins local users to domain users with automatic profile migration for the current user. This ensures the retention of current local user settings, such as wallpaper, Internet Explorer settings, Power Option Settings, and desktop items, in their new domain environment. Optionally, you can choose not to migrate.For bulk deployment, you can compile the script to .exe with PowerGUI to bypass Powershell Execution Policy.
What this script will do:
1) It will check connection to 2 DNS servers listed in script header section.
2) If DNS Check is OK, it will check DNS settings of your machine network adatpers against the IP addresses listed in script header section. If not match, it will prompt the user & try to change the DNS settings. If you have multiple network adapters it will ask for each adapter.
3) If the DNS settings is not changed, the script will show errors for Administrator permission and exits.
4) It will ask for user approval and then it will join to domain.
5) If domain join is succeed, it will ask the user to migrate current user’s profile to new domain user’s profile.
6) If the user choose to migrate current profile, the current user’s SID and new domain user’s SID are backup to txt file in user’s
home directory.
7) After that it will prompt the user to restart the computer.
Note:
Supported from powershell v2.0. Tested on Windows7, Server2008R2. Not supported in Windows 10 because it ends up with a flickering screen after login. So, for windows 10, you can use USMT tools instead.
If running script is disabled on this system..” error occurrs, you need to change the execution policy in powershell as below.
Open the elevated powershell console and type Set-ExecutionPolicy Unrestricted

Cannot change DNS setting of network cards, permission denied

Figure-1: DNS setting incorrect & permission denied to change the DNS setting

 
Join domain by powershell script

Fig-2: user1 join to domain

Domain User Logged in

Fig-3: Restart the computer and Domain User test1 logged in

You can download my script from github.

This entry was posted in Active Directory, Powershell. Bookmark the permalink.

1 Response to Script to Join Active Directory Domain with Local user Profile migration

  1. Anonymous says:

    On win 10 after run script successful and restart. When login with user domain. It sign out and go back login screen. Can you fix it. Thank you!

Leave a Reply

Your email address will not be published. Required fields are marked *