Powershell to Re-join a machine to the domain

By Rory Monaghan


Here’s a pretty simple, quick script which quickly re-joins your machine to the domain. You run the script, the machine will reboot and you will then be able to login using your domain credentials again.

$psmachine = Get-WmiObject Win32_ComputerSystem
$psmachine.UnJoinDomainOrWorkGroup(“PASSWORD”, “USERNAME”, 0)
$psmachine.JoinDomainOrWorkGroup(“DOMAIN” , “PASSWORD”, “USERNAME”, $null, 3)
Restart-Computer -Force

Note: The USERNAME in both rows is just the username and NOT Domain\Username. Obviously passing a username and password in plain text is never a good thing. Frankly this is so small, I just copy and paste, create the script and run it from the machine in question as I need it. It’s quicker than joining the machine to the WORKGROUP and then re-joining to the domain, in my opinion!

Hope this is useful for some of you!

Let's make virtualization easier!

Be amongst the first to know when I publish new reviews, guides and tools to simplify your projects.

By signing up, you agree to our Terms of Use and acknowledge the data practices in our Privacy Policy. You may unsubscribe at any time.