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 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 :
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".
In user container, you can see a username , whose name is "root".
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.
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.
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
Deployment of the MOF file is finished.
it's time to verify
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. ,
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.
Cool ! Isn't
That's all for today, see you in my next blog post.
Thanks
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”.
Hi, how can i add a group member with a space in it?
ReplyDeleteExample:
Ensure = 'Present'
GroupName = 'AmanTestGroup'
Members = 'root users'