Thursday, April 17, 2014

Write your First Desired State Configuration Script using ROLE 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.


a-alphabet-kids-coloring-pictures-printablefter, so much of theory, it is time to write our first real “Desired State Configuration” script. 


 I am going to break this blog post in to two parts, in the first part we  will write a simple “DSC” configuration script and in second part we will run the script and see the result.


What is the purpose of our this “DSC” script?


I have  just installed a fresh windows 2008 Server on my machine, I do install “XPS Viewer” and “PowerShell ISE” in all of servers.  

Our “DSC” script will install these  two windows features for us stated below.

1.      XPS Viewer

2.      PowerShell ISE


Note: PowerShell 4.0 is installed on both machines, on the client machine in which  we are going to write the script, and on the Server on which we are going to push the configuration.


Machine configurations


Windows 2008 Standard Edition, with PowerShell 4.0 installed.

16-04-2014 19-06-43



Windows 8.1 , with PowerShell 4.0 Installed

16-04-2014 19-07-56



Let’s get started.

Step one: run your PowerShell-ISE as an “Administrator”


When you run “PowerShell-ISE” as an “Administrator”, the console path is set to “C:\Windows\System32” by default.


16-04-2014 19-25-57


Please change the console path

to “C:\users\YourNAME\Documents\WindowsPowerShell\Modules". The reason for changing the

console path is, “when we execute the DSC configuration script, it creates a folder and generates

MOF file and we don’t want to end up creating files and folders in the “C:\Windows\System32


16-04-2014 19-27-17


Configuration Script.





Configuration myServerRoles {


    Node 'Posh-Demo'



            #Installing XPS viewer.


            WindowsFeature xpsViewer




             Name = 'XPS-Viewer'


             Ensure = 'Present'





            # installing PowerShell ISE to the Server


            WindowsFeature 'powerShellISE'




            Name = 'PowerShell-ISE'


            Ensure = 'Present'











16-04-2014 19-59-03


1. We start  with writing script using “Configuration” keyword followed by the name of the configuration, I am using “myServerRoles. This name can be any string name.


2.  I am mentioning the “Node” keyword to providing my sever name “Posh-Demo” for which we are writing the configuration.


3. We are using the “Role Resource of the DSC” which had the keyword “Windowsfeature” and followed by the name, this name can be any string.


4. The Name can be anything for “WindowsFeature” script block.


5 & 6. They are the declrations of the "WindowsFeature” DSC resource.

7.      In “Name” ,we have to provide the “Exact name of the Windows feature or Role which we are planning to install

8.      In “Ensure” , we are provide the value of either “Present” or “Absent”.



In my next Windowsfeature Script block, I will configure it to install the “PowerShell-ISe” feature. The syntax and declaration is almost same, except the name of the feature to Install.

Note : You can read more about “Role” DSC resource from this link :

Our configurations script seems simple and easy to write. What? You have a question?


Ok, ask.........


How to find the name of the windows feature?


Very nice question. Let me describe it a bit more. :)


To know the list of all Windows Features, go to your server, Open the PowerShell and hit this cmdlet.


Get-WindowsFeature , and it will give you the name of all available features and roles; we can use these names in  "WindowsFeature"  resource block in DSC configuration scripts


16-04-2014 19-24-43



Let, me explain few tips regarding window features.


  • In Point 1, we are seeing the names of all windows features available, while writing DSC scripts, you have to use these Names, liked “AD-Cerificate”, “ADLDS”, and “DHCP” etc.
  • There are 2 Types of window features, the first type of features are those that have sub features, like you are seeing in point2, “Active Directory Certificate Service” have 4 sub features, if you want to install “active Directory Certificate Service” with sub features, you have to Set  IncludeAllSubFeature = $true in the DSC configuration Script.



    Sample script with sub features should be look like this.


  • The second type of windows features are those, which have no “Sub features”, in the point 3, you can see that FAX feature doesn’t have any sub feature.


    Our, Configuration Script is ready"!. Smile 


    In our next blog post we will see this script in Action.


    Thanks for your time and I hope that you will find this post helpful.





    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”.


    1. Buy cheapeast Washing Machine at Sargam Electronics in delhi-ncr.
      Sargam Electronics

    2. What about useful writing advices, might be useful for you. It was really helpful when I tried to write my literary analysis essay.

    3. Very useful info!
      I want to share too
      Speedypaper - the best essay writing service.
      Check it up!

    4. Thanks for this useful post.
      If you need help with your assignment or paper this essay writing service can help.