Tuesday, April 1, 2014

Introduction of Windows PowerShell "Desired State Configuration"

 

Did you heard about “PowerShell DSC”?  NO?  

You must me kidding me!!

Come on, these days it is more famous and in demand compare to “ clip_image002 Justin Bieber” and “clip_image004 Shakira” ;)

 

Ok, jokes a part.

 

PowerShell DSC is the most uber-cool feature in PowerShell v4.

I love it.

It is introduced as the part of “Windows PowerShell V4”{wmf 4.0}.

Why you care? And what it do for you?

 

If you are lazy administrator, then it is a blessing for you, if you are busy administrator then it is a robot for you to help you out. It is a very good way to manage our IT infrastructure.

As an example, you can automate the whole process of deploying website using DSC, from installing IIS, configuring them, and copy your website content to the IIS server.

specs09

Imagine, you just need to create a script once and that’s all, you can use it with any or many servers.

DSC a new management platform for windows PowerShell, you just need to declare how you want to configure your software environment and it will do the rest for you.  

You can also set dependencies, for example, you can set that website won’t be copied, until IIS is not installed).

 DSC syntax is declarative and it make maintaining the configuration much easier.

 

Convinced? Yes? Good.

 

DSC work with resource providers, by default there are 12 resource providers in WMF 4.0. You can also create your custom resource and providers too.

List of Default Resources in WMF 4.0

Provider

Description

Windows PowerShell Desired State Configuration Archive Resource

Unpacks archive (.zip) files at specific paths on target nodes.

Windows PowerShell Desired State Configuration Environment Resource

Manages system environment variables on target nodes.

Windows PowerShell Desired State Configuration File Resource

Manages files and directories on target nodes.

Windows PowerShell Desired State Configuration Group Resource

Manages local groups on target nodes.

Windows PowerShell Desired State Configuration Log Resource

Logs configuration messages.

Windows PowerShell Desired State Configuration Package Resource

Installs and manages packages, such as Windows Installer and setup.exe packages, on target nodes.

Windows PowerShell Desired State Configuration Process Resource

Configures Windows processes on target nodes.

Windows PowerShell Desired State Configuration Registry Resource

Manages registry keys and values on target nodes.

Windows PowerShell Desired State Configuration Role Resource

Adds or removes Windows features and roles on target nodes.

Windows PowerShell Desired State Configuration Script Resource

Runs Windows PowerShell script blocks on target nodes.

Windows PowerShell Desired State Configuration Service Resource

Manages services on target nodes.

Windows PowerShell Desired State Configuration User Resource

Manages local user accounts on target nodes.

 

DSC Resource Kit Waves

 

To add the extra resources, you can download the DSC Resource Kit Wave1, Wave2, and Wave3 too. These Wave kits has extra configuration resources apart from 12 default resources.

 

DSC Resource Kit wave 1

http://blogs.msdn.com/b/powershell/archive/2013/12/26/holiday-gift-desired-state-configuration-dsc-resource-kit-wave-1.aspx

 

 

Resource

Description

xComputer

Name a computer and add it to a domain/workgroup

xVHD

Create and managed VHDs

xVMHyperV

Create and manage a Hyper-V Virtual Machine

xVMSwitch

Create and manage a Hyper-V Virtual Switch

xDNSServerAddress

Bind a DNS Server address to one or more NIC

xIPAddress

Configure IPAddress (v4 and v6)

xDSCWebService

Configure DSC Service (aka Pull Server)

xWebsite

Deploy and configure a website on IIS

 

 

DSC Resource Kit wave 2

http://blogs.msdn.com/b/powershell/archive/2014/02/07/need-more-dsc-resources-announcing-dsc-resource-kit-wave-2.aspx

 

Resource

Description

Module Name

xADDomain

Create and manage an Active Directory Domain

xActiveDirectory

xADDomainController

Create and manage an AD Domain Controller

xActiveDirectory

xADUser

Create and manage an AD User

xActiveDirectory

xWaitForADDomain

Pause configuration implementation until the AD Domain is available.  Used for cross machine synchronization.

xActiveDirectory

xSqlServerInstall

Create and manage a SQL Server Installation.

xSqlps

xSqlHAService

Create and manage a SQL High Availability Service.

xSqlps

xSqlHAEndpoint

Create and manage the endpoint used to access a SQL High Availability Group.

xSqlps

xSqlHAGroup

Create and manage a SQL High Availability Group.

xSqlps

xWaitForSqlHAGroup

Pause configuration implementation until a SQL HA Group is available.  Used for cross machine synchronization.

xSqlps

xCluster

Create and manage a cluster.

xFailOverCluster

xWaitForCluster

Pause configuration until a cluster is available.  Used for cross machine synchronization.

xFailOverCluster

xSmbShare

Create and manage a SMB Share.

xSmbShare

xFirewall

Create and manage Firewall rules

xNetworking

xVhdFile

Manage files to be copied into a Vhd.

xHyper-V

xWebsite

Added functionality to xWebsite to support configuration of https websites.

xWebAdministration

xVhd

Bug fixes

xHyper-V

 

DSC Resource Kit wave 3

http://blogs.msdn.com/b/powershell/archive/2014/03/28/dsc-resource-kit-wave-3.aspx

 

Module

Resource

Description

xWebAdministration 

xWebAppPool

Create, remove, start, stop an IIS Application Pool

xWebVirtualDirectory

Create or remove a virtual directory

xWebApplication

Create or remove a web application

xWebConfigKeyValue

Configure AppSettings section of Web.Config

xDatabase 

xDatabase

Create, drop & deploy databases

xDBPackage

Backup & restore databases

xSystemSecurity 

xUAC

Enable or disable User Account Control prompt

xIEEsc

Enable or disable IE Enhanced Security Configuration

xRemoteDesktopSessionHost 

xRDSessionDeployment

Creates and configures a deployment in RDSH. 

xRDSessionCollection

Creates a RDSH collection. 

xRDSessionCollectionConfiguration 

Configures a RDSH collection. 

xRDRemoteApp

Publish applications for your RDSH collection

xPSDesiredStateConfiguration 

xWindowsProcess

Adds ability to run as a specific user to the existing WindowsProcess resource 

xService

Update to existing Service resource to include create/configure service

xRemoteFile

Download files from a URI

xPackage

Adds ability to run as a specific user to the existing resource, includes VS Setup

xArchive

Create, update, extract a Zip file

xEndpoint

Creates a remoting endpoint

Updates

xDscResourceDesigner, xComputer, xVMHyperV, xDNSServerAddress

Feature additions and bug fixes

 

Naming conventions,

 

The resource and modules those names are started with “X” are means they are experimental, and those resource and modules are starts with “c” means, they are supported and provided by community. Microsoft reserve resourced and module name without any prefixed (“x”,”c”) for future use, if you are going to create you own custom resources, make sure, you can add some “prefix” in it for safe side J

 

How it works.

 

There are few steps to make DSC working

1.      Create a DSC Configuration script.

2.      Execute DSC configuration script.

a.      When we run the configuration script, it produce a MOF file.

3.      Deploy it

a.      Using Pull Method

                                                              i.      HTTP

                                                            ii.      HTTPS

b.      Using Push Method

                                                              i.      Manual Method

 

When we deploy the MOF files to the node (computers), they will start configuring themselves.  

Managed Object Format

DSC is has a dependency on MOF, when we run  the DSC configuration script  it export the “MOF” document file.

So what is the MOF?

As per Microsoft documentation “Managed Object Format (MOF) is the language used to describe Common Information Model (CIM) classes.

            Source : http://msdn.microsoft.com/en-us/library/aa823192(v=vs.85).aspx

 

 

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

Thanks .

thank you circle sentiment- paulaposts

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. Are we able to use DSC for SQL DBAs? In terms of new builds both physical and virtual? Does it come with parameters to change up and then just fire off?


    Thanks

    ReplyDelete