The Below PowerShell script can be used Remove (Unjoin) Windows Server from Active Directory Domain
#!powershell
# Setup Key Values
###################################
$AD_DEPLOYMENT_ID = “YourLogin”
$AD_DEPLOYMENT_PASSWORD = “YourPassword”
$AD_DOMAIN_TO_UNJOIN = “knowledgeascent.com”
$HOSTNAME = $env:computername
# Remove SERVER from AD Domain
###################################
$cred = New-Object System.Management.Automation.PsCredential(“$AD_DEPLOYMENT_ID”, (ConvertTo-SecureString “$AD_DEPLOYMENT_PASSWORD” -AsPlainText -Force))
write-host ” “
write-host “unjoin Computer $HOSTNAME from domain $AD_DOMAIN_TO_UNJOIN” -ForegroundColor Yellow
write-host ” “
Remove-Computer -ComputerName $HOSTNAME -UnjoinDomainCredential $cred -Workgroup Local -Restart -Force