[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

Remove/rejoin computer to domain via Powershell script?

Posted on 2014-12-29
5
Medium Priority
?
13,616 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 20

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 1332 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 668 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 1332 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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

In the absence of a fully-fledged GPO Management product like AGPM, the script in this article will provide you with a simple way to watch the domain (or a select OU) for GPOs changes and automatically take backups when policies are added, removed o…
A walk-through example of how to obtain and apply new DID phone numbers to your cloud PBX enabled users that are configured in Office 365. Whether you have 1, 10 or 100+ users in your tenant, it's quite easy to get them phone-enabled and making/rece…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…

649 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