Thursday, April 3, 2014

Getting Started With Desired State Configuration: DSC Syntax

Quotes

1.  Introduction of Windows PowerShell "Desired State Configuration"
2.  Installing Windows PowerShell 4.0 [Windows Management Framework 4.0]

The Windows PowerShell Desired State Configuration is mainly contains three parts.

1.      Configuration Block

a.      Support Parameters too using Param( ).

2.      Node Block

a.      We can have one or more “Node Blocks”

3.      Resource Block

a.      We can have one or more “Resource Blocks”

 

"Configuration Block"

 

In Windows PowerShell DSC Microsoft has introduced a new keyword, naming it as “Configuration”.  All magic is doing here.  The Syntax of “Configuration” is almost same as Windows PowerShell “Function”.

To configure DSC in our environment, we need to define a script block first, starts with keyword “Configuration” then a string Value / Name for the configuration and opening and closing braces ({ }) .

 

Configuration anyName {

 

 

 

 

}

 

clip_image001

 

Node Block

 

Inside the “Configuration Block”, we have to define another block name as “Node Block”. In this block we define the name of the computers on which we are going to apply “Desired Stare Configuration” and export MOF file.

In “Configuration Block”, can have one more Node Blocks.

The Syntax of “Node Block” is simple, is starts with “Node” keyword, then name of the computer, then opening and closing braces ({ }).

 If we want to deploy DSC on more than one computer, we can use a comma separated list encapsulated in brackets ( ). We can also use variable in computer name position.

Rest of everything will be goes inside the curly braces of the “Configuration”  script block.

 

     Node "myServer-01" {

 

 

 

  

     } #closing brace for Node

 

clip_image001[4]

Mentioning multiple computers.

   Node ("myServer-01","MyServer-02") {

 

 

 

  

     } #closing brase for Node

 

 

clip_image002

It should be look this.

clip_image001[6]

 

"Resource Block"

 

Inside the “Node block”, we have to specify the “Resource Block”. A “Resource Block” starts with a name of Resource like “File”, ”Archive”  etc.,  following the string identifier / name, and then opening and closing braces ({ }).

We can have multiple Resource Blocks in a “Node Block” . Inside the “Resource Block” we declare the properties and value of the resource.

"Node Block" can have one or more resources blocks.

 

            WindowsFeature MyExampleFeature 

                

             {

 

                   

                   

             } #Closing brase for WindowsFeature MyExampleFeature

 

clip_image002

Normally it will look this with without parameterizing.

03-04-2014 11-21-00

"Parameterizing Configuration Script"

 

We can also parameterizing the DSC configuration script like functions. We just need to use the Param( ) and then we can define our parameters inside it.

 

  Configuration anyName

{

 

 Param (

 [string[]]$myServer = "Server-01"

 )

 

    Node $myServer

       {

 

            WindowsFeature MyExampleFeature 

             {

 

                   

                   

             } #Closing brase for WindowsFeature MyExampleFeature

     

 

      } #closing brase for Node

 

 

 

} #Closing brase for Configuration

 

03-04-2014 12-47-19

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

thank-you-all

 

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

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.