Showing posts with label Powershell Automation. Show all posts
Showing posts with label Powershell Automation. Show all posts

Tuesday, May 12, 2015

Managing Windows Server 2012 R2 Using PowerShell : Part-1 : Windows Server 2012 R2 Installation.

 

Part - 1

From past few weeks, I was thinking about a topic for blogging. I want to choose a topic for "System Administrators" those are either working in a small-business firms and not moved to cloud yet.

Then yesterday my Manager asked me to test a "Windows Server 2012 R2" server, at that moment a idea clicked me, to start an series on "Managing Windows Server 2012 by using PowerShell". I personably liked this idea and I am sure that you are going to like it too.

This series it going to be  in four parts.

  1. Installation.
  2. Information.
  3. Configuration.
  4. Management.

Graph

Installation.

In installation, we are going to install a Windows Server 2012 R 2 from scratch, We  are not going to use any fancy thing to install it. Just a plain simple installation of the server ( the next, next , next thingy). This part with not contain any PowerShell fun ( Sorry).

Information.

In information section, we are going to check the various default settings of the server, and we try to got those setting, by using PowerShell and we are going to set various settings using PowerShell too. This is where the fun will start begins.

Configurations.

In this Section we are going to deal with Server Roles and other cool stuff. In this section we are going to install few core server roles and try to set their configurations by using PowerShell cmdlets or scripts.

Management.

 In Management section, we are going to create reports on various server things, We are going to write scripts and lot's of other cool stuff.

5-12-2015 11-56-53 AM INSTALLATION.

The installation of "Windows Server 2012 R2" is straight forward process. Most of us are already aware of it and may have already installed Server 2012 R2 few times.

But I would like to share every step so if someone who has never installed Windows Server 2012 before can be benefited from this post.

For the installation of the server, I am using "Windows Server 2012 R2" ISO image, and I am  installing this operating system on a virtual machine which is hosted on VMware ESxi server. 

I booted my virtual machine from the server's ISO image and when it booted from ISO image, I asked me for set Language, Time & Currency and keyboard type, I choose default for now and clicked on Next.

5-12-2015 12-00-49 PM

After clicking NET, the below screen will come, now click on "Install Now" to begin the installation process.

5-12-2015 12-01-03 PM

After the "Install now" , the next screen is to  "choose the operating system to install".

In the choice of operating systems to install, I am choosing "Windows Server 2012 R2 (Server with a GUI), Click on the desired operating system of choice and then click on NEXT

5-12-2015 12-08-14 PM

The next screen is "Licence Agreement", Accept the EULA (by ticking the checkbox) and then click on "NEXT".,

5-12-2015 12-09-48 PM

The next screen is  "Which type of installation do you want?" if we were upgrading the server then I might choose the Upgrade , but this is a new and fresh installation, so , I have chosen "Custom" .

5-12-2015 12-18-31 PM

When we clicked on "Custom" option to install, it brings a DISK management window, in which either we can delete the previous build partitions, or create / Format a new one. If you can see in the below screenshot, that we have a raw/unallocated disk space & I don't want to create any partition, I would like to have a single 40GB disk drive.

So i just selected the "Drive 0" and click on NEXT.

5-12-2015 12-19-11 PM

After clicking the next, the installation of Windows Server 2012 R2 will begin.

5-12-2015 12-19-41 PM

When the windows setup is complete and installation is finished, it rebooted the server and after booting it started  asking  to provide a Password for Administrator user account.

I have provided the password P@$$w0rd . now Click Next

5-12-2015 11-31-43 AM

Once you have provided the password, it will started finalizing the settings and configuration of the server..

5-12-2015 12-26-04 PM

Once the all settings are done, it will prompt us to login to the Server (yayyyyy!).

5-12-2015 12-26-21 PM

This virtual machine is connected to real network and also to the internet. When I login to the machine for the first time, it got the IP Address from my DHCP server, and asked if i liked to run "Network Discovery" Now. I don't like to run it now, so I choose "No".

5-12-2015 12-27-04 PM

Now, our server is up and running and Operating System is installed successfully.

5-12-2015 11-34-58 AM

Now our next step is to get and set some information on this server by using PowerShell, which we are going to  do in  our next blog post.

The PowerShell fun is going to start from the next posts onwards, stay tuned.

Tare care till then.

CharSahibJadey

Regards.
Aman Dhally
If you like, you can follow me on Twitter and Facebook. You can also check my “You Tube channel for PowerShell video tutorials. You can download all of my scripts from “Microsoft TechNet Gallery”.

Thursday, May 8, 2014

Using Windows PowerShell Desired State Configuration Registry Resource

 

1.  Introduction of Windows PowerShell “Desired State Configuration”.

2.  Installing Windows PowerShell 4.0 [Windows Management Framework 4.0].

3.  Getting Started With Desired State Configuration: DSC Syntax.

4.  Review of Desired State Configuration: The 3 easy steps.

5.  Write your First Desired State Configuration Script using ROLE Resource.

6.  Run your first "DSC" PowerShell Script.

7.Configuring Dependencies in "Desired State Configuration" script in PowerShell.

8.PowerShell and DSC : Using File Resource

 

In my previous blog post, we have seen how to use, "Desired State Configuration File Resource".

Today we are going to use "Desired State Configuration Registry Resource".

The registries are a very good way to keep the information.

I have created my own Registry keys folder on my local servers, in which I do keep a track of the various information for example, when the server was build, in which geographical location is the server located etc..

The Syntax of "Registry Resource" is.

08-05-2014 19-05-12

Let's get started.

We are going to write a new DSC script today. The name of the script is "SettingRegistry".

In this DSC configuration script, we are created two Registry Resource Script block.

In first script block, we are creating  a new Registry Key folder name as "IT Internal" and adding a new Key name as "Geographical Location" and setting it's value to "New Delhi, India".

In our second script block, we are creating a another key name as "ServerBuildversion" and setting the key value to "2.0".

We will deploy this configuration to our favourite guinea pig server "Posh-Demo".

You can check in the below screenshot, that currently there is NO key exists as the name of "ITinternal".

08-05-2014 12-16-31

You can check the below DSC script. The script is very simple to understand.

 

Ensure = Present # That means it has to be there.

Key = "HKEY_LOCAL_MACHINE\Software\ITInternal" # The path to the Key, if the ITinternal key folder  doesn't exists, it will get created automatically.

ValueName = "Geographical Location" # The Name of the Key which you want to Create.

ValueData = "New Delhi, India" # the value of the ValueName key, which we have mentioned above.

Force = $true # if the key already exists overwrite it.

ValueType = "String" # What kind of value we are storing, the valid options are,  { Binary | Dword | ExpandString | MultiString | Qword | String }

 

My script.


Configuration settingRegistry
{
Node 'Posh-Demo'
{
Registry serverGEOlocation
{
Ensure = 'Present';
Key = 'HKEY_LOCAL_MACHINE\Software\ITInternal'
ValueName = 'Geographical Location'
ValueData = 'New Delhi, India'
Force = $true
ValueType = "String"


}


Registry ServerBuid
{
Ensure = 'Present';
Key = 'HKEY_LOCAL_MACHINE\Software\ITInternal'
ValueName = 'ServerBuildVersion'
ValueData = '2.0'
Force = $true
ValueType = "String"

}



}
}

settingRegistry
You can see that our two script blocks clearly marked below. 

08-05-2014 12-17-10


 


Now, run the script. and it will export the MOF file.


08-05-2014 12-19-51


Start deploying it using Start-DscConfiguration cmdlet.


Start-DscConfiguration -Path .\settingRegistry -Wait -Verbose


08-05-2014 12-23-22


You can see that  it finishes deploying MOF file, and that's in just 2.23 seconds. Wow! 


08-05-2014 12-24-10


Now, let's check our server and see if the desired registry entries get created or not.


You can see in below screenshot of the server,  that all registry keys, which we configured in DSC script are created successfully.


We all love "Desired State Configuration", Isn't Smile 


08-05-2014 12-24-48



I am hoping that you may find this blog postings useful.


ThankYou (2)


Regards


Aman Dhally


If you like, you can follow me on Twitter and Facebook. You can also check my “You Tube channel for PowerShell video tutorials. You can download all of my scripts from “Microsoft TechNet Gallery”.