Problem Description : Windows 10 unable to join domain
Solution: When you invoke a script to join Windows 10 machine to domain, the domain joining process may fail.
Assuming you are running a script something like “add-computer -computername $computer -Domain $DomainToJoin -Credentials $domainCredentials -LocalCredentials $localcredentials” to join Windows 10 machine to domain. The script may fail to execute completely. If you manually run same script on the Windows 10 machine that is interactive session, it will successfully execute the script; however invoking the script on remote computer (Windows 10) will fail.
This happens because when you invoke script remotely, the response received from domain controller is not accepted by Windows 10, because it is not interactive session, Windows 10 assumes that it never initiated domain joining process. The work-around to this issue is to temporary disable the firewall. You can add a script block in your scrip to disable firewall before starting domain joining process and then another script block to enable firewall after domain joining process.
To disable firewall -> “Set-NetFirewallProfile -Profile Public -Enabled False”
To enable firewall -> “Set-NetFirewallProfile -Profile Public -Enabled True”