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 on my Server Core .
2. Adding my Physical Host running Server 2012 to the domain

Step 1. Deploying domain 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 "" 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 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 ""  -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

Now, I have a domain "" 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 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 "" and DNS "" to the Hyper-V Internal Adapter with ifindex "18"....wondering how ? see my previous post do it via Shell. 

Now get the Net IP Configuration
  Now, If you try Test-Connection (dexservercore) it shows it's online....But when you do this
Test-Connection dexservercore and Test-connection 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 "" it should not go to the Internet rather my inernal network having 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.    dexterservercore

So now whenever I try to contact or dexservercore it just resolves the IP address from here (Oh! Wait it means the 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 on my server core (dexservercore) and my physical host (dexterposh) is connected to the domain and internet is running fine to just prove it get the connection profile...

That's all for now...

Monday, October 22, 2012

Assigning Static IP Address to the Server Core

Now for the first time you boot a Server get nothing but a Command Shell (cmd.exe).
Now before we begin further let's assign a static IP address to the Server Core VM.

REMINDER : My Lab has server named "DexterPOSH" Server 2012( on Physical Host) and then in Hyper-V a VM named "dexservercore" running Server Core 2012.

Open "Hyper-V Manager" and Right-Click and "Connect" to the VM (start it if it is not started yet)

There are actually three ways to do this..You may be familiar with all three maybe but I wanted to list all the ways to do this.

1. Using Netsh utility - this one is old school

But this one is depreciated see the screenshot below..It's recommending PowerShell ( will cover it in 3rd step)

anyways to set the IP address..first get your interface by using :

Now I have the interface with me...Time to set the IP address (old school)

Okey done.

2 . Using Sconfig utility - Server 2K8 R2 way

Now this Sconfig utility was introduced in Server 2008 R2 to easily get the Server Core up and bring it on the network , to enable the server management remotely. Type Sconfig in the cmd.exe and hit Enter.

Following screen shows up :

Now if you look at the options this one is a great utility to do simple configuration on the Server Core.
Now my IP Address is already set from above Netsh example..But I will still go and show you how to do it.

Press 8 to change the "Network Settings" then it will list the available Network Adapter. Choose the Index# to change the settings on that Network Adapter.

After selecting the Network Adapter. It will list the set of actions that can be performed on the Network Adapter..go ahead and select "1".

After this select the type of IP Address you want, we want the static IP address "S" and then type in the IP Address...easy !

3. The PowerShell Way .. :)

Go the Cmd.exe and typer "Start PowerShell" to get the PowerShell console ....(Yay! Finally )
Now put the POSH console in the foreground.....Let's do this

Now First of all get all the network adapters using Get-NetAdapter...(PowerShell 3.0 dynamically loads the module so no need to load the Net* modules for this)

Then once you have the Adapter status ...go ahead and set the IP Address using New-NetIPAddress cmdlet. I used -whatif before actually using the cmdlet to be sure....then remove -whatif and perform the operation
Refer help for New-NetIPAddress.

Note that if the IP is already set then the New-NetIPAddress cmdlet throws an error. To show this and remove already present IP settings....what I did was use Remove-NetIPAddress cmdlet to remove the earlier settings.

Phewww..! This post went long....Thanks for bearing me (if you made this far).

Choose the method that fits you best..(hopefully the PowerShell way)



Sunday, October 21, 2012

Server 2012 and Server Core...New Plan

I am taking this new initiative to learn Server 2012 along with Server Core.....

Lab Setup:
I have VHD booted Server 2012 with full blown GUI on my Physical Machine (Name - DexterPOSH).
Then I have enabled the Hyper-V role on my this machine and installed a Server Core 2012 on a VM created in the Hyper-V (Name - DexServercore).

Along doing this Lab Setup, I came to learn cool things and I want to share them:

Step 1: Download the trial Server 2012 iso.

Step 2: I have a Windows 7 box , so to test the Server 2012 I am going to VHD Boot the Server 2012 for 180 days (license period) then delete the VHD and the boot entry. Here is a great article on how to do this for Windows 8 but the steps are the same for Server 2012 too.

Step3: Once you have VHD Booted your machine to Server 2012. Open our favorite PowerShell console and run the following to install Hyper-V role on the host

 Get-WindowsFeature -name *hyper* | Install-WindowsFeature

Reboot your machine to complete Hyper-V installation

Step 4: After reboot, create a new VM in Hyper-V

But before we do this we need to create a virtual switch using PowerShell v3, I am going to create a new internal network switch

New-VMSwitch -Name "internal network" -SwitchType Internal

Once the switch is created use this when creating the New VM :

New-VM -Name "ServerCore" -VHDPath D:\VHD\ServerCore.vhd -MemoryStartupBytes 1024MB -BootDevice IDE -SwitchName "Internal Network"

Step 5: Now the VM is created ...I need to add the Server Core iso to the VM and Boot it

Add-VMDvdDrive -VMName ServerCore –Path D:\ISOs\ServerCore.iso 

Start-VM -Name "ServerCore"

Now Boot the VM by going to Hyper-V manager and Connect to the VM and complete the installation.

 Following is a  ScreenShot of my Lab, Note that the Server Core is running in the VM ..Cool !

P.S. - Now there is another method which can be used.....Follow the VHD boot article(shared in step 2)  and apply the appropriate WIM Image from the ISO to the VHD of the New VM and you are good to go too :)

That's all for now, will keep posting what I try on this setup.


Thursday, October 18, 2012

Resuming Blogging...

I was busy learning PowerShell and attending PowerShell events in India.
Now, I am a member of New Delhi PowerShell User Group and Bangalore PowerShell User Group.
I blogged occasionally for New Delhi PowerShell UG on Citrix and PowerShell.

Just to get a hint of my inactivity on this blog.......

I think I am back for good now.....