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.
fter, so much of theory, it is time to write our first real “Desired State Configuration” script.
I am going to break this blog post in to two parts, in the first part we will write a simple “DSC” configuration script and in second part we will run the script and see the result.
What is the purpose of our this “DSC” script?
I have just installed a fresh windows 2008 Server on my machine, I do install “XPS Viewer” and “PowerShell ISE” in all of servers.
Our “DSC” script will install these two windows features for us stated below.
1. XPS Viewer
2. PowerShell ISE
Note: PowerShell 4.0 is installed on both machines, on the client machine in which we are going to write the script, and on the Server on which we are going to push the configuration.
Machine configurations
Server
Windows 2008 Standard Edition, with PowerShell 4.0 installed.
Client
Windows 8.1 , with PowerShell 4.0 Installed
Let’s get started.
Step one: run your PowerShell-ISE as an “Administrator”
When you run “PowerShell-ISE” as an “Administrator”, the console path is set to “C:\Windows\System32” by default.
Please change the console path
to “C:\users\YourNAME\Documents\WindowsPowerShell\Modules". The reason for changing the
console path is, “when we execute the DSC configuration script, it creates a folder and generates
MOF file and we don’t want to end up creating files and folders in the “C:\Windows\System32”
directory.
Configuration Script.
Configuration myServerRoles {
Node 'Posh-Demo'
{
#Installing XPS viewer.
WindowsFeature xpsViewer
{
Name = 'XPS-Viewer'
Ensure = 'Present'
}
# installing PowerShell ISE to the Server
WindowsFeature 'powerShellISE'
{
Name = 'PowerShell-ISE'
Ensure = 'Present'
}
}
}
myServerRoles
1. We start with writing script using “Configuration” keyword followed by the name of the configuration, I am using “myServerRoles. This name can be any string name.
2. I am mentioning the “Node” keyword to providing my sever name “Posh-Demo” for which we are writing the configuration.
3. We are using the “Role Resource of the DSC” which had the keyword “Windowsfeature” and followed by the name, this name can be any string.
4. The Name can be anything for “WindowsFeature” script block.
5 & 6. They are the declrations of the "WindowsFeature” DSC resource.
7. In “Name” ,we have to provide the “Exact name of the Windows feature or Role which we are planning to install”
8. In “Ensure” , we are provide the value of either “Present” or “Absent”.
In my next Windowsfeature Script block, I will configure it to install the “PowerShell-ISe” feature. The syntax and declaration is almost same, except the name of the feature to Install.
Note : You can read more about “Role” DSC resource from this link : http://technet.microsoft.com/en-us/library/dn282127.aspx
Our configurations script seems simple and easy to write. What? You have a question?
Ok, ask.........
How to find the name of the windows feature?
Very nice question. Let me describe it a bit more. :)
To know the list of all Windows Features, go to your server, Open the PowerShell and hit this cmdlet.
Get-WindowsFeature , and it will give you the name of all available features and roles; we can use these names in "WindowsFeature" resource block in DSC configuration scripts
Let, me explain few tips regarding window features.
Sample script with sub features should be look like this.
Our, Configuration Script is ready"!.
In our next blog post we will see this script in Action.
Thanks for your time and I hope that you will find this post helpful.
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.