I have a Windows machine that has been cloned and to keep it from overwriting DNS entries it has only port 3389 enabled. What I am currently doing is using the GUI to join a workgroup and then renaming the computer before re-joining the domain. This works when done through the GUI but when done via Powershell it fails to leave domain and join workgroup.

I was attempting to use:

Add-Computer -WorkGroupName MyWorkGroup

However this gives the error:

 Add-Computer : Failed to unjoin computer from domain with the following error message: The
specified domain either does not exist or could not be contacted.

I though perhaps running Powershell as the local Administrator might work, but that encountered the same error. I though maybe using the cached domain admin account might work, but also get the same error. I thought maybe specifying any or all of the Credential/LocalCredential/UnjoinDomainCredential parameters might help but that yielded no luck either.

It seems like there has to be a way to do this through Powershell that I am overlooking. Any advice is appreciated.

  • 1
    Perhaps an obvious question, but can you maybe disjoin it before you leave the domain?
    – Zoredache
    Mar 4, 2019 at 19:36
  • @Zoredache Unfortunately I cannot disjoin it first. The clone is created from a backup of a production system.
    – LK86
    Mar 4, 2019 at 19:38
  • I haven't used that command in that type of situation, but have you tried passing a -force? Worst case, it may be that you could use netdom. serverfault.com/questions/511317/…
    – Zoredache
    Mar 4, 2019 at 19:42
  • @Zoredache -force did not work but the netdom command did work. Thank you!
    – LK86
    Mar 4, 2019 at 21:26

1 Answer 1


I am not that sure if this works, but you may want to give it a try by using:

Remove-Computer -ComputerName "Server01" -UnjoinDomainCredential Domain01\Admin01 -WorkgroupName "Local" -Restart -Force

Microsoft Documentation : Remove-Computer

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.