The below PowerShell script can be used to Join Windows Server to Active Directory Domain

#!powershell

# Setup Key Values
###################################
$AD_DEPLOYMENT_ID = “YourLogin”
$AD_DEPLOYMENT_PASSWORD = “YourPassword”
$AD_DOMAIN_TO_JOIN = “knowledgeascent.com”
$AD_DOMAIN_OU = “OU=trainingscripts,DC=knowledgeacent,DC=com”
$HOSTNAME = $env:computername

# Join SERVER to AD Domain
###################################

$cred = New-Object System.Management.Automation.PsCredential(“$AD_DEPLOYMENT_ID”, (ConvertTo-SecureString “$AD_DEPLOYMENT_PASSWORD” -AsPlainText -Force))

write-host ” ”
write-host “Join Server $HOSTNAME to domain $AD_DOMAIN_TO_JOIN” -ForegroundColor Yellow
write-host ” “

Add-Computer -DomainName $AD_DOMAIN_TO_JOIN -Credential $cred -OUPath “$AD_DOMAIN_OU”

# Restarting SERVER
##############################
write-host ” “
write-host “Restarting Server $HOSTNAME” -ForegroundColor Yellow
write-host ” “
Restart-Computer -Force