Thursday, January 16, 2014

Part 2–: PowerShell and DHCP : DHCP Post-Install Configuration


Part – 1 : PowerShell and DHCP : Installing DHCP Server Role on Server 2012

Doing Post-Install Configuration tasks


In my previous post, we go through the steps for installing the DHCP Server role on our windows server 2012. In this post we are going to do the DHCP Post Configuration tasks, which contains two steps for a standalone (Workgroup) server.
1.       Creating Security Groups
a.       DHCP Administrators
b.      DHCP Users
2.       Supressing the post-install configuration alert.

Note: I am running a non-domain server, which is just a standalone workgroup computer, if you want to do post-installation configuration on domain joined server, than the few steps are different as per compared to the workgroup server.

After installing the DHCP server roles, we have to complete the DHCP Server Post installation tasks. 

So, when you open the server manager console, you will see the below warning error, “Configuration required for DHCP Server at DHCP-Server1.

1

When you click on it, it will ask you to complete an action to Complete DHCP Configuration.

2
When you click on “Complete DHCP configuring”, you will see that it will ask to create 2 Security groups, one is “DHCP Administrators” and another one is “DHCP Users”.
Now Click on Cancel, yes on Cancel and go back to our PowerShell Console.

3

As, I told you before, that we will try to configure DHCP Server using PowerShell as much as we can.

Note : With Server 2012 R2, you can use the Add-DHCPServerSecurityGroup to add the two groups.No need to manually add them using ADSI! (Thanks to Sir Thomas Lee for suggestions.

Now, run the below script and then open Local users and Groups.

# Creating a group for DHCP Server
   # This Step is required for WorkGroup only server,
   # If your server is joined to the Domain, this steps are not valid.

$objectOU = [ADSI]"WinNT://$env:COMPUTERNAME"
$group = $objectOU.Create("Group","DHCP Users")
$group.CommitChanges()

$groupAdmin = $objectOU.Create("Group","DHCP Administrators")
$groupAdmin.CommitChanges()


4

Once you run the above script, you, can see that desired groups are created.

5

But, when you open Server Manager Console again you will see the same error again.

6

To supress this error, we need to change a registry settings, and then we need to restart the DHCP Server Service.
Run the below command to change the Registry value, to change the registry value, run the below command.

Set-ItemProperty -Path HKLM:\SOFTWARE\Microsoft\ServerManager\Roles\12 -Name ConfigurationState -Value 2

7

Now, restart the DHCP Server Service.
Restart-Service -Name DHCPServer –Force

8

Now, open Server Manager again, and you can see there are not errors related to “DHCP Server Post Configuration”.
9

That’s all.
Now our POST configuration task is done, now next we have to start configuring the server…


Regards
Aman Dhally
clip_image017 clip_image018 clip_image019 clip_image020  clip_image021


Thursday, January 9, 2014

Part – 1 : PowerShell and DHCP : Installing DHCP Server Role on Server 2012

New PowerShell Series

After publishing my “Event Logs and PowerShell” series, I am posting another PowerShell article series, this article series is on installing, configuring, maintain DHCP Server using PowerShell.

In this series, we will configure a DHCP Server from scratch and we configure it using PowerShell. We will try to use as much as PowerShell as we can.

Side by side, we also try to generate a small simple script, those are help us to automate the whole deployment.

Background

If you are a system administrator like me, our main job is to configuring and deploying servers with different or same server roles.

Sometime with a different configurations and sometime with exactly the same configuration of another servers.

 For example if you are about to deploy a DHCP Server in any of your regional office or local office, I am sure that most of the settings will remain same like other DHCP servers.

Rather than doing the same thing manually again and again, we will use PowerShell to automate it, in this series, I will start configuring DHCP sever from the PowerShell console, but in the end we will try to write a small script to automate the whole manual task.

Specification

I am going to use Windows Server 2012 as a DHCP Server, and a windows 7 as client system, both are the virtual machine those are running on windows Hyper-V.

Configuration

Our DHCP Server configuration should be simple. The below is the list of task which we are going to do.

1.       Install the DHCP role on Server 2012

2.       Configure

a.       DHCP Scope

b.      Authorise Server

c.       Configure DNS Option

d.      Configure Router Option

e.      Configure DNS Domain Name option

f.        See if we manage to set Reservation

3.       Start DHCP Server

4.       Test it

May be we added more task, if needed arise.

Note

Before installing the DHCP serve role, make sure your would be DHCP server has STATIC IP Address, otherwise you will get the below warning error while installing the DHCP server role.

clip_image002[5]

Installing DHCP Role

 

Our first step is to install the DHCP role, but before installing the serve role, we have to check  if the role is already installed or not.

We can use Get-WindowsFeature cmdlet to check which role are currently Installed, or Available to install or Removed.

clip_image003

 

We are interested in installing, the DHCP server role.  You can see that DHCP Role is available but not installed.

clip_image005

 

Now using let’s check for DHCP Server Role Only, you can see in the below output that the DHCP role is available but it is  not installed.

Get-WindowsFeature -Name 'DHCP'

clip_image007

 

Now, let’s install DHCP Server Role, by using the cmdlet “Install-WindowsFeature”.  And in             –Name  parameter, we have to provide the Name of server role as argument , which role we want to install, in our case it is “DHCP”.

Install-WindowsFeature -Name 'DHCP' –IncludeManagementTools

 

clip_image009

 

clip_image010[5]

 

Once the command run successfully. You can see that the EXIT code is showing Success and value of success is True. That means DHCP Server role in installed successfully.

clip_image012[5]

Let’s run Get-WindowsFeature -Name 'DHCP'again to verify if role is installed or not.

Now you can check that install State of server role in installed now.

clip_image014[5]

 

Now, when you open server manager, and in Roles and features you can see a DHCP Server role is there, and you can see in that You have a new DHCP option available underneath all Servers option.

 

clip_image016[5]

 

And when you click on them, you can see all things related to DHCP.

 

clip_image018[5]

 

When you click on Tools, you can see the DHCP , option there.

clip_image020[4]

 

And when you click on it DHCP manager will open.

clip_image022[4]

 

 

That’s all for today, see you in the next post.

 

 

Regards
Aman Dhally
clip_image017 clip_image018 clip_image019 clip_image020  clip_image021

 

 

 

 

 

 

 

Monday, January 6, 2014

Part-7: Working with Event Logs using PowerShell :- Clearing Event Entries and Removing Event Log.

 

Part-1: Working with Event Logs using PowerShell

Part–2 : Working with Event Logs using PowerShell :- Get-EventLog

Part–3 : Working with Event Logs using PowerShell :- Get-EventLog

Part–4 : Working with Event Logs using PowerShell :- Get-WinEvent

Part–5 : Working with Event Logs using PowerShell :- Get-WinEvent

Part–6 : Working with Event Logs using PowerShell :- Creating New Event Logs and Event Entries

 

 

 

In my previous post, we talk about the usage of, New-EventLog and Write-EventLog, and we are almost at completion of this series.

Today we are going to use two more PowerShell cmdlets, Clear-EventLog and Remove-EventLog.

 

Clear-EventLog

 

It’s a very simple cmdlet, if you want to clear all event entries from any event log, you can use Clear-EventLog to clear it.

In our “MyPoshShell” event log, you can see there are 4 event entries. Let’s clear our event log.

Note: You have to run these cmdlets as Administrator.

clip_image002

 

Clear-EventLog -LogName 'MyPoshShell'

 

clip_image004

 

Now let’s see if out log is cleared or not, and indeed it is. You can see there are no event entries in the log now.

clip_image006

 

 

Remove-EventLog

 

It’s also another straight forward cmdlet like Clear-EventLog, usage is very simple, type the cmdlet and provide the name of the event log, which you want to delete.

This cmdlet remove complete log, not just entries.

Let’s remove our previously created “MyPoshLog”.

Remove-EventLog -LogName 'MyPoshShell'

Once you run the cmdlet, open the “Event Viewer” and see if logs is still their ;o) .

clip_image007

When you check, our “MyPoshShell” log is not there anymore.

clip_image008

 

 

I hope you have enjoyed this series J .

I hope I will come soon with another series.

 

Regards
Aman Dhally
clip_image017 clip_image018 clip_image019 clip_image020  clip_image021