Solved

Remove/rejoin computer to domain via Powershell script?

Posted on 2014-12-29
5
7,381 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
5 Comments
 
LVL 18

Expert Comment

by:Peter Hutchison
Comment Utility
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
Comment Utility
Ok, but howto do this remotely?
0
 
LVL 5

Accepted Solution

by:
GG VP earned 333 total points
Comment Utility
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 82

Assisted Solution

by:oBdA
oBdA earned 167 total points
Comment Utility
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
Comment Utility
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

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

Exchange server is not supported in any cloud-hosted platform (other than Azure with Azure Premium Storage).
HOW TO: Install and Configure VMware vSphere Hypervisor 6.5 (ESXi 6.5), Step by Step Tutorial with screenshots. From Download, Checking Media, to Completed Installation.
This Micro Tutorial will give you a basic overview of Windows DVD Burner through its features and interface. This will be demonstrated using Windows 7 operating system.
This video shows you how to use a vSphere client to connect to your ESX host as the root user. Demonstrates the basic connection of bypassing certification set up. Demonstrates how to access the traditional view to begin managing your virtual mac…

762 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

Need Help in Real-Time?

Connect with top rated Experts

6 Experts available now in Live!

Get 1:1 Help Now