Join server into windows domain PS script
$username = "ad-domainadmin" $Password = "mypassword" $pwd = $Password | ConvertTo-SecureString -asPlainText -Force $credential = New-Object System.Management.Automation.PSCredential($UserName,$pwd) $Domain = "ad.domain.com" Add-Computer -DomainName $Domain -Credential $credential –Restart
Remove server from windows domain PS script
$username = "ad-domainadmin" $Password = "mypassword" $pwd = $Password | ConvertTo-SecureString -asPlainText -Force $credential = New-Object System.Management.Automation.PSCredential($UserName,$pwd) $Domain = "ad.domain.com" Remove-Computer -UnjoinDomaincredential $credential -Force –Restart