Today I ran into an issue where I needed to remove some servers from the domain, perform some tasks and add them again. Adding a server to the domain is very common, use the Add-Computer cmdlet like this:
Add-Computer -DomainName MyDomain.tld
Or even this to change the computer name in the process:
Add-Computer -DomainName MyDomain.tld -NewName server34
To remove a computer from the domain and add it to a workgroup we can use the Remove-Computer cmdlet:
Remove-Computer -Workgroup temp
Remove-Computer -Workgroup temp -Force -Restart
Makes sense, doesn't it? Don't forget to use an elevated prompt (Run as Administrator) or all you will see is an Access Denied error.