This command will use the current user to change the membership on the device, the domain credentials to join the device to the domain, place it in the correct OU and do a reboot to complete the process. Don’t want to use the current user but you want to specify one? No problem, use the –LocalCredential parameter.

See how easy this has become? But… what if you wanted to unjoin a server from a domain and rejoin it to another domain (a fairly common migration scenario)? I won’t even post the VB code in there for that since that’s just spamming… nor will I post the PowerShell v2 code. Let’s go straight to the PowerShell v3 solution for this:

See how the domain credential of the old domain is used as the local credential? I’ve done this in this example to show you that domain credentials can be used as local credentials when the device is already a member of that domain. So why would you use domain credentials for that? Easy… when you want to unjoin/join multiple devices with one single command: