Thursday, May 15, 2014

How to Use Windows PowerShell Desired State Configuration Group 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

9.Using Registry Resource

10. Using Archive Resource.

In my previous blog post, we have seen that  how can we use the "Archive Resource" of "Desired State Configuration".

It's time to create some new local groups and local users. In this blog post we are going to create a new LOCAL group.

We can create local groups using the "Group Resource" of the "Desired State Configuration". Always keep in mind that "Group Resource" creates only LOCAL groups only it won't support creating in new Domain groups.

"Group Resource" resource is very simple to configure and simple to use.

Syntax of the Group Resource is :

 

14-05-2014 15-51-17

 

Let's start.

What we are planning to achieve?

We are going to write an simple Desired State Configuration Script, which have a "Group Resource" block. In this script we, are creating a new Local Group, we also setting it's description, and after that we are also adding one local user to this newly created group. That's all.

For testing we are using our all time favourite server "Posh-Demo" again.

Open Server Manger on the Server , Click  Local User and Group Option on the "Posh-Demo"  server, Click on Groups and You can see that currently there is no group of the name of "AmanTestGroup".

14-05-2014 15-41-15

In user container, you can see a username , whose name is "root".

14-05-2014 15-41-53

Now, we have user, we need to create a new group,

The below is our "Desired State configuration script".

The Name of our DSC script is DSC_CreatingNewGroups.ps1.  And the name of our DSC configuration is "createNewGroup".

We are using  "Group Resource" of Desired State Configuration. Below is the parameters and there arguments details.

Ensure : Make sure it is present .

GroupName : Name of the desired group.

Member : Name of the local user groups, whom you want to add to this group.

Description : Description of the group.

14-05-2014 15-43-20

Configuration createNewGroup
{


Node 'Posh-Demo'
{
Group testGroup
{
Ensure = 'Present'
GroupName = 'AmanTestGroup'
Members = 'root'
Description = "This group is created by PowerShell DCS script"


}
}
}
createNewGroup


Run the script, and it will generate the MOF file.


14-05-2014 15-43-46


Once, the MOF file is generated, we need to deploy it using, Start-DscConfiguration cmdlet.


Start the deployment of the MOF file using "Start-DscConfiguration"


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


 


14-05-2014 15-44-31


Deployment of the MOF file is finished.


14-05-2014 15-44-57


it's time to verify Smile 


Open Server Manger on the Server , Click  Local User and Group Option on the "Posh-Demo"  server, Click on Groups and and you can  see that group is created. ,


14-05-2014 15-45-39


If you check the properties of the group, you can see that , Description is set as we define it in our DSC script.and it also added the ROOT user to the group.


14-05-2014 15-46-09


Cool ! Isn't


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


Thanks


thank-you (3)


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

1 comment:

  1. Hi, how can i add a group member with a space in it?

    Example:

    Ensure = 'Present'
    GroupName = 'AmanTestGroup'
    Members = 'root users'

    ReplyDelete

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