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 post, we have seen , how to use the "User Resource" of the "Desired State Configuration".
Today, we are going to see how to use the "Service Resource" of the "Desired Sate Configuration".
It's a very useful resource, I do like it very much, you can set and and configure services as per you own need, and using this DSC script, you can configure service as you want them on your servers.
The Syntax of the Service Resource is :
What we are going to do today?
By using the "Service Resource", we are going to change the "Virtual Disk" service's start-up mode from "Manual" to "Automatic".
We also changing the "State" of "Virtual Disk" service from "Stopped" to "Running".
You can see that the usage of the "Service Resource" is very straight forward.
In my Script, the name of the script is "DSC_ServiceResourceDemo" .The name of the Configuration block is "settingServices". and the name of the "Service Resource" block is "virtualDiskService".
Name = Actual name of the Service, for example , the actual name of "Virtual Disk" service is "vds".
State : Set the running state of the Service, either it can be "Running" or "Stopped".
StartupType : The Startup type can be either, "Automatic", "Disabled", or "Manual".
Script.
Configuration settingServices
{
Node 'Posh-Demo'
{
Service virtualDiskService
{
Name = 'vds'
State = 'Running'
StartupType = 'Automatic'
}
}
}
settingServices
Start-DscConfiguration -Path .\settingServices -Wait -Verbose
In the below screenshot, you can see that ,the command finishes successfully. Let's check, if the changes which we configured in the script, are applied successfully or Not.
Yay! They are applied successfully.
If you want to run the Service using any of these there built-in-account. You can use the "BuiltInAccount" parameter and the provide the below options as a string argument.
- LocalService
- LocalSystem
- NetworkService
BuiltInAccount = "NetworkService"
Now, run the DSC script again, when the MOF file created, deploy it again using the same process like above.
If the pushing of the MOF is successful, you can see that the "Log On As" account of the Service is set to the "Network Service" now.
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”.
No comments:
Post a Comment
Note: Only a member of this blog may post a comment.