Bruce Adamczak

I have spent years working in perfmon, so I thought I would share some tips and tricks on the tool!

Windows 2012 Core Survival Guide – Joining the Domain

Windows 2012 Core Survival Guide – Joining the Domain

  • Comments 2
  • Likes

Learn about my 2012 Core Survival Guide here.

Joining the Domain

Everybody at some point will need to join their computers to the domain.  This blog will cover the basics of viewing your settings, joining the domain and removing your computer from the domain.

How to view Domain Settings

We can view the domain name by using a WMI object Win32_ComputerSystem.  I still looking for a good way to do this native with PowerShell 3.0

PowerShell Command:

(Get-WmiObject Win32_ComputerSystem).domain

The output below shows the domain name of the computer.  In this case it is "WORKGROUP"

 

How to join the computer to the Domain

By joining your computer to the domain you will get all of the benefits that the domain has to offer.  The PowerShell cmdlet we use is “Add-computer”.

PowerShell Command:

Add-computer -DomainName Contoso.com -Credential Contoso\Administrator -Restart

The output below of the first command shows the current domain name of the computer.  In this case it is "WORKGROUP".  The second command joins the computer to the domain Contoso.com.  In addition, the second command will prompt you for credentials of an account with domain join privileges in the domain you are trying to join.

 

How to Join a Domain and place the computer in an Organizational Unit (OU)

Most corporations have well defined OU structures and do not want computer objects place in the default folder.  By placing the computer object in the correct OU saves you time.  Below is the cmdlet that will help us with that.  You must know the complete distinguished name (spelling counts here) of the OU you wish to place the computer into.  If the distinguished name has any spaces in it you must quote the entire name.  I found it makes my life easier to always quote the distinguished name.

PowerShell Command:

Add-computer -DomainName Contoso.com -OUPath "OU=Servers, OU=Assets,DC=Contoso,DC=COM" -Credential Contoso\Administrator -Restart

The output below of the first command shows the current domain name of the computer.  In this case it is "WORKGROUP".  The second command joins the computer to the domain Contoso.com in the OU "Servers".  In addition, the second command will prompt you for credentials of an account with domain join privileges in the domain you are trying to join.  The computer will reboot when the command is completed.

 

 

How to leave a Domain

When you leave a domain you default back to the “Workgroup”

PowerShell Command:

Remove-Computer -UnjoinDomaincredential Contoso\Administrator -Passthru -Verbose -Restart 

The output below of the first command shows the current domain name of the computer.  In this case it is "Contoso.Com".  The second cmdlet will remove it from the domain.  In addition, the second command will prompt you for credentials of an account with domain join privileges in the domain you are trying to leave.  Finally when the command completes the computer will reboot.

 

 

 

I hope you found this useful.  Please leave me a comment.  Let me know if there are any core tasks you would like me to cover.

Bruce

 

Comments
  •  Nice post

  • Thanks :)

Your comment has been posted.   Close
Thank you, your comment requires moderation so it may take a while to appear.   Close
Leave a Comment