Saturday, October 15, 2016

Script to Join Active Directory Domain with Local user Profile migration

Writing a long good script is a tire-some job as well as interesting on the look & feel. It's been a quite a long time I didn't write good script whilst spending time with tiny utility scripts in my work. Today, I finalized a very good script which will join local users to domain users with automatic profile migration(current user) so that it will keep current local user's settings (such as wallpaper, Internet Explorer settings, Power Option Settings and their items on the desktop) in their new domain environment. And optionally you can choose not to migrate. For bulk deployment, you can compile the script to .exe with PowerGUI to bypass Powershell Execution Policy. Comments or feedbacks are welcome :D
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 and Windows 10 machines.
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



Figure-1: Permission error & DNS Servers connection error


Figure-2: user1 join to domain

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






1 comment:

  1. 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!

    ReplyDelete

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