Sunday, October 28, 2012

Deploying AD Domain using PowerShell + Completing LAB Setup

I would like to divide this post in two parts :
1. Deploying a domain dexter.com on my Server Core .
2. Adding my Physical Host running Server 2012 to the domain dexter.com.


Step 1. Deploying domain dexter.com on my Server Core.

First of all I need to add the Active Directory Domain Services role in my Server Core. To get the Active Directory Roles on my Server Core use the following cmdlet


The highlighted entry shows that the AD-Domain-Services Role is already installed on my Server Core. But if it is not then you can issue the following to install it.

Install-WindowsFeature -Name AD-Domain-Services -IncludeManagementTools

Now the role is installed and till Server 2K8 R2 , one would have gone and run the dcpromo.exe (this one is deprecated now with Server 2012) but here I will try to use PowerShell ..this is the link I followed


Windows Server 2012 has a new module named " ADDSDeployment" and if I check the cmdlets supplied:

 
You get the idea...Now I am going to setup a Forest with the domain "dexter.com" this one is all in my internal Hyper-V network...Remember I added a internal virtual switch using the Add-VMSwitch cmdlet in this Post.

Now my best clue is Install-ADDSForest will do the job, so let's kick the help first :


But wait there is one cool cmdlet Test-ADDSForestInstallation which runs the prerequisites (only) for installing a new forest in Active Directory . You can try this but anyways when you .

##########################################################################
But Wait what's the Secret to all this learning...I sure didn't came up with all this..What I did is as under.

Now what I really did was fire-up server manager on my Server 2012 with GUI (base machine) ..
Click on "Promote this Server to a Domain Controller"



Next a wizard similar to dcpromo.exe shows up



Now in next few pages set the password, domain and forest functional level etc and then finally there will come a screen like the following ....



Now click on the "View Script" to get the equivalent PowerShell script that will do the same changes as you selected in the Wizard...Now use this script (after appropriate changes..ofcourse ) to deploy the Forest on your Server Core....Cool way to learn , eh !

Following is the Script I executed in my Server Core to install the domain dexter.com...I haven't done any changes like changing the Domain and Forest Functional Level but this may change according to your needs.
Import-Module ADDSDeployment
Install-ADDSForest -CreateDnsDelegation:$false -DatabasePath "C:\Windows\NTDS" `
-DomainMode "Win2012"  -DomainName "dexter.com"  -DomainNetbiosName "DEXTER" `
-ForestMode "Win2012" -InstallDns:$true -LogPath "C:\Windows\NTDS" `
-NoRebootOnCompletion:$false -SysvolPath "C:\Windows\SYSVOL" -Force:$true




Step 2. Adding my Physical Host running Server 2012 to the domain dexter.com.

Now, I have a domain "dexter.com" running in my Hyper-V internal network. But the problem is I am connected to a public network on my Physical Host with Server 2012...and through which I access internet.

So here is what I did to add my physical machine (DexterPOSH) to the domain dexter.com and still access the Internet

First let's check the Net Adapter's on my DexterPOSH machine ...


I have renamed the Adapter as "Internet" to indicate that I access Internet through it using Rename-NetAdapter cmdlet. Now assign the IP "192.168.1.1" and DNS "192.168.1.2" to the Hyper-V Internal Adapter with ifindex "18"....wondering how ? see my previous post ...to do it via Shell. 

Now get the Net IP Configuration
 
  Now, If you try Test-Connection 192.168.1.2 (dexservercore) it shows it's online....But when you do this
Test-Connection dexservercore and Test-connection dexter.com....what it does is it looks out through your internet connected address and resolve the IP address.

What I want is that whenever my Machine tries to reslove "dexter.com" it should not go to the Internet rather my inernal network having dexter.com domain on machine dexservercore. There may be a various ways to do this but the simplest solution I tried was to edit the hosts file at location C:\Windows\System32\Drivers\etc\hosts and add the following entry to it.

192.168.1.2    dexter.com
192.168.1.2    dexterservercore


So now whenever I try to contact dexter.com or dexservercore it just resolves the IP address from here (Oh! Wait it means the dexter.com on the Internet can't be resolved by my system now..Guess will have to live with that.. :) :D lol ).

 Now a better way can be to add DNS Server Role to my phsical machine add an entry for it. But this one is simple and effective and works fine too... :)

Last, step now is to add my machine to the domain. Issue the following on the Shell :

   
So the end result is I have a domain dexter.com on my server core (dexservercore) and my physical host (dexterposh) is connected to the domain dexter.com and internet is running fine too....so to just prove it get the connection profile...



 
That's all for now...

1 comment: