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 :
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.
Ensure = 'Present'
GroupName = 'AmanTestGroup'
Members = 'root'
Description = "This group is created by PowerShell DCS script"
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.