Executing Desired State Configuration (Advanced)

Exclusive offer: get 50% off this eBook here
Instant Windows PowerShell Guide [Instant]

Instant Windows PowerShell Guide [Instant] — Save 50%

Enhance your knowledge of Windows PowerShell and get to grips with its latest features

$14.99    $7.50
by Harshul Patel | November 2013 | Enterprise Articles

This article written by Harshul Patel, the author of the book Instant Windows PowerShell Guide, describes what needs to be done rather than covering imperative syntax and specifies how a task can be performed.

(For more resources related to this topic, see here.)

DSC approaches declarative syntax that describes what needs to be done rather than covering imperative syntax that specifies how a task can be performed.

Getting ready

To use DSC, first define a desired configuration. Like functions, configurations in DSC can be defined in the Windows PowerShell language by using the Configuration keyword and stored in script (.ps1) or module (.psm1) files. Also, similar to functions, configurations need to be defined and then run.

How to do it...

  1. To use a configuration, invoke the Configuration block the same way you would invoke a Windows PowerShell function, passing in any expected parameters you have defined (two in the preceding sample). For example, in this case, the MyWebConfig configuration can be invoked as follows:

    PS C :\>MyWebConf -MachineName $env:COMPUTERNAME –WebsitePath
    \\PSShare\MyWebSites

    This will create a folder with the same name as your configuration name and will contain our MOF output file.

  2. The following command creates an MOF file known as the configuration instance document. Path represents the target directory where your MOF files are located. Wait causes the execution of the DSC resources to run in the background, that is, an interactive process.

    PS C :\>Start-DscConfiguration -Path .\ MyWebConf –Wait –Verbose

How it works...

Each Configuration block must have at least one Node block. Each Node block can have one or more resource provider blocks. You can use the same role provider more than once in the same Node block.

In addition to new language keywords, DSC includes the following set of CMDLETs for managing configurations:

  • Start-DscConfiguration: This CMDLET deploys a configuration to one or more target nodes and applies the configuration on those nodes by using the local configuration manager
  • Get-DscConfiguration: This CMDLET returns the current configuration from one or more target machines:

    PS C :\>$Sess = New-CimSession -ComputerName localhost PS C :\>Get-DscConfiguration –CimSession $Sess

  • Restore-DscConfiguration: This CMDLET restores the current configuration from one or more target machines:

    PS C :\>$Sess = New-CimSession -ComputerName localhost PS C :\>Restore-DscConfiguration –CimSession $Sess

There's more…

There is one more CMDLET that helps to detect the configuration drift:

  • Test-DscConfiguration: This CMDLET checks for one or more target nodes and returns a Boolean value indicating whether the current desired state matches the actual state. Have a look at the following command:

    PS C :\>$session = New-CimSession -ComputerName localhost PS C :\>Test-DscConfiguration –CimSession $session

    This will either return True when the current and actual configuration matches or False if there's a mismatch

Summary

In this article, we learned about how to execute the new feature introduced with the release of Windows PowerShell v4.0—Desired State Configuration.

Resources for Article:


Further resources on this subject:


Instant Windows PowerShell Guide [Instant] Enhance your knowledge of Windows PowerShell and get to grips with its latest features
Published: November 2013
eBook Price: $14.99
See more
Select your format and quantity:

About the Author :


Harshul Patel

Harshul Patel is a technology enthusiast from India; he is thoroughly knowledgeable in virtualization and cloud computing techniques. He works for a leading service-based organization that has an alliance relationship with vendors such as Citrix and Microsoft. Harshul holds multiple Microsoft certifications, including Microsoft Certified Solutions Associate (Windows Server 2012 and Windows 8) and Microsoft Certified Solutions Expert (Private Cloud). Additionally, he holds non-Microsoft certifications, such as Citrix Certified Administrator (XenApp 6.5, XenDesktop 5.6, and XenServer 6.0) and Citrix Certified Advanced Administrator (XenApp 6.5).

He is one of the early adopters of Windows PowerShell from India. He frequently lectures on Windows PowerShell in user-group gatherings and delivers trainings (mostly on PowerShell) across the organization. He is also a proud recipient of multiple faculty awards and an innovation award from his employer. He is a core member of PowerShell Bangalore User Group (http://powershellgroup.org/bangalore.india) and a member of New Delhi PowerShell User Group (http://powershellgroup.org/NewDelhi). He can be contacted at harshulpatel.com.

Books From Packt


 Instant Windows Powershell 3.0 Windows Management Instrumentation Starter [Instant]
Instant Windows Powershell 3.0 Windows Management Instrumentation Starter [Instant]

Microsoft Windows PowerShell 3.0 First Look
Microsoft Windows PowerShell 3.0 First Look

Microsoft SharePoint 2010 and Windows PowerShell 2.0: Expert Cookbook
Microsoft SharePoint 2010 and Windows PowerShell 2.0: Expert Cookbook

 Windows Server 2012 Automation with PowerShell Cookbook
Windows Server 2012 Automation with PowerShell Cookbook

 Windows Server 2012 Unified Remote Access Planning and Deployment
Windows Server 2012 Unified Remote Access Planning and Deployment

SQL Server 2012 with PowerShell V3 Cookbook
SQL Server 2012 with PowerShell V3 Cookbook

 Microsoft Exchange Server 2013 PowerShell Cookbook: Second Edition
Microsoft Exchange Server 2013 PowerShell Cookbook: Second Edition

 PowerShell 3.0 Advanced Administration Handbook
PowerShell 3.0 Advanced Administration Handbook


No votes yet

Post new comment

CAPTCHA
This question is for testing whether you are a human visitor and to prevent automated spam submissions.
b
6
3
n
w
x
Enter the code without spaces and pay attention to upper/lower case.
Code Download and Errata
Packt Anytime, Anywhere
Register Books
Print Upgrades
eBook Downloads
Video Support
Contact Us
Awards Voting Nominations Previous Winners
Judges Open Source CMS Hall Of Fame CMS Most Promising Open Source Project Open Source E-Commerce Applications Open Source JavaScript Library Open Source Graphics Software
Resources
Open Source CMS Hall Of Fame CMS Most Promising Open Source Project Open Source E-Commerce Applications Open Source JavaScript Library Open Source Graphics Software