Solved

Remove/rejoin computer to domain via Powershell script?

Posted on 2014-12-29
5
11,459 Views
Last Modified: 2014-12-29
Hi,

I need to revert to an ESXI vmware snapshot of a vm all the time.
Regularely I get the message "trust relationship between this workstation and the domain failed".
I need to remove it from the domain, reboot add it to the domain reboot what is ennoying.

Please advise howto do this in an easier way, via Powershell or other?

J.
0
Comment
Question by:janhoedt
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
5 Comments
 
LVL 19

Expert Comment

by:Peter Hutchison
ID: 40521487
Use the Add-Computer command:
e.g.
$name = $Env:ComputerName
$cred = Get-Credential
Add-Computer -WorkgroupName WORKGROUP -ComputerName $name
Add-Computer -Domain domain-name -Credential $cred -ComputerName $name
0
 

Author Comment

by:janhoedt
ID: 40521490
Ok, but howto do this remotely?
0
 
LVL 5

Accepted Solution

by:
GG VP earned 333 total points
ID: 40521521
You can use Remove-Computer to remove the computer from domain,

http://technet.microsoft.com/en-us/library/hh849816%28v=wps.620%29.aspx

Parameter Set: Remote
Remove-Computer -UnjoinDomainCredential <PSCredential> [-ComputerName <String[]> ] [-Force] [-LocalCredential <PSCredential> ] [-PassThru] [-Restart] [-Workgroup <String> ] [ <CommonParameters>]

PS C:\> Remove-Computer -ComputerName Server01 -UnjoinDomainCredential Domain01\Admin01 -Workgroup Local -Restart -Force
0
 
LVL 85

Assisted Solution

by:oBdA
oBdA earned 167 total points
ID: 40521523
Easier solution to prevent this from happening in the first place: create a GPO applied only to this VM (by security filtering or a separate GPO), in which you enable the "Domain member: Disable machine account password changes" policy (http://technet.microsoft.com/en-us/library/cc785826(v=ws.10).aspx).
Restore the snapshot, re-join the restored machine one last time to the domain (btw: you can save yourself the first reboot; remove from domain, close the dialogs, re-open the dialog, rejoin, reboot), open rsop.msc to make sure the policy is applied, then take a new base snapshot.
0
 
LVL 5

Assisted Solution

by:GG VP
GG VP earned 333 total points
ID: 40521528
You can use Add-Computer to join the computer to domain,

http://technet.microsoft.com/en-us/library/hh849798(v=wps.620).aspx

Syntax:

Parameter Set: Domain
Add-Computer [-DomainName] <String> -Credential <PSCredential> [-ComputerName <String[]> ] [-Force] [-LocalCredential <PSCredential> ] [-NewName <String> ] [-Options <JoinOptions> ] [-OUPath <String> ] [-PassThru] [-Restart] [-Server <String> ] [-UnjoinDomainCredential <PSCredential> ] [-Unsecure] [-Confirm] [-WhatIf] [ <CommonParameters>]

Open in new window


Example:

This command adds the Server01 computer to the Domain02 domain. It uses the LocalCredential parameter to specify a user account that has permission to connect to the Server01 computer

PS C:\> Add-Computer -ComputerName Server01 -LocalCredential Server01\Admin01 -DomainName Domain02 -Credential Domain02\Admin02 -Restart -Force

Open in new window

0

Featured Post

Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

When asking a question in a forum or creating documentation, screenshots are vital tools that can convey a lot more information and save you and your reader a lot of time
Windows 10 Creator Update has just been released and I have it working very well on my laptop. Read below for issues, fixes and ideas.
Windows 10 is mostly good. However the one thing that annoys me is how many clicks you have to do to dial a VPN connection. You have to go to settings from the start menu, (2 clicks), Network and Internet (1 click), Click VPN (another click) then fi…
Finding and deleting duplicate (picture) files can be a time consuming task. My wife and I, our three kids and their families all share one dilemma: Managing our pictures. Between desktops, laptops, phones, tablets, and cameras; over the last decade…

724 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question