Continuing with the tradition of holiday gifts to the PowerShell community, the PowerShell team has just released DSC Resource Kit Wave-1 - a set of PowerShell modules that contain DSC resources and example configurations. The various modules that are part of DSC Resource Kit Wave 1 can be found here.
When DSC was introduced in PowerShell v4, we shipped a set of built-in resources. However one of the important features of DSC is the ability to create custom resources in PowerShell. Our previous blog posts detail how to author resources and how to deploy resources. In order to encourage the community to create more DSC resources and help boot strap the authoring process, we are releasing this first wave.
We have introduced a new naming convention for these modules and resources – they contain an “x” in them like xWebAdministration, MSFT_xWebsite, etc. The “x” stands for experimental – which means these resources are provided AS IS and are not supported through any Microsoft support program or service. We will monitor these, take feedback and may provide fixes on a “fix forward” basis – that is to say we may simply republish with fixes in future. I am deliberately using the word “may” to indicate no guarantees of any sort. However, you are free to adapt these to your environment and make changes as necessary.
Description of Resources
To discover all the resources available as part of the resource kit, use the Get-DSCResource cmdlet:
PS D:\> Get-DscResource -Name x* | Format-Table Name, Module, ImplementedAs -AutoSize
Name Module ImplementedAs
---- ------ -------------
xComputer xComputerManagement PowerShell
xVHD xHyper-V PowerShell
xVMHyperV xHyper-V PowerShell
xVMSwitch xHyper-V PowerShell
xDNSServerAddress xNetworking PowerShell
xIPAddress xNetworking PowerShell
xDSCWebService xPSDesiredStateConfiguration PowerShell
xWebsite xWebAdministration PowerShell
Here is a brief description about each of the resource
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 |
Making Changes to Resources
When making changes to these resources, we suggest the following practice:
1. Update the following names (replace MSFT with your company/community name and remove the “x”):
a. Module name (ex: MSFT_xWebAdmnistration becomes Contoso_WebAdministration)
b. Resource Name (ex: MSFT_xWebsite becomes Contoso_Website)
c. Resource Friendly Name (ex: xWebsite becomes Website)
d. MOF class name (ex: MSFT_xWebsite becomes Contoso_Website)
e. Filename for the <resource>.schema.mof (ex: MSFT_xWebsite.schema.mof becomes Contoso_Website.schema.mof)
2. Update module and metadata information in the module manifest
3. Update any configuration that use these resources
As specified in the license, you may copy or modify this resource as long as they are used on the Windows Platform.
Requirements
The DSC Resource Kit requires Windows 8.1 or Windows Server 2012 R2 with update KB2883200 (aka the GA Update Rollup). You can check whether it is installed by running the following command:
PS C:\WINDOWS\system32> Get-HotFix -Id KB2883200
Source Description HotFixID InstalledBy InstalledOn
------ ----------- -------- ----------- -----------
NANA-TOUCH Update KB2883200 NANA-TOUCH\Admini... 9/30/2013 12:00:00 AM
On supported down level operating systems, they require WMF 4.0. Refer to these previous blog posts for more information on WMF 4.0 and issues with partial installation.
Configurations using Resources from DSC Resource Kit
Once the resources are deployed, they can be used in configurations. An example configuration is given below (this example together with the sample website files are available as part of the examples of xWebAdministration module):
ConfigurationFourthCoffeeWebsite
{
param
(
# Target nodes to apply the configuration
[Parameter(Mandatory)]
[ValidateNotNullOrEmpty()]
[String[]]$NodeName,
# Name of the website to create
[Parameter(Mandatory)]
[ValidateNotNullOrEmpty()]
[String]$WebSiteName,
# Source Path for Website content
[Parameter(Mandatory)]
[ValidateNotNullOrEmpty()]
[String]$SourcePath,
# Destination path for Website content
[Parameter(Mandatory)]
[ValidateNotNullOrEmpty()]
[String]$DestinationPath
)
# Import custom resources from the module that defines it
Import-DscResource-ModulexWebAdministration
Node $NodeName
{
# Install the IIS role
WindowsFeature IIS
{
Ensure ="Present"
Name ="Web-Server"
}
# Install the ASP .NET 4.5 role
WindowsFeature AspNet45
{
Ensure ="Present"
Name ="Web-Asp-Net45"
}
# Stop the default website
xWebsite DefaultSite
{
Ensure ="Present"
Name ="Default Web Site"
State ="Stopped"
PhysicalPath ="C:\inetpub\wwwroot"
DependsOn ="[WindowsFeature]IIS"
}
# Copy the website content
File WebContent
{
Ensure ="Present"
SourcePath =$SourcePath
DestinationPath =$DestinationPath
Recurse =$true
Type ="Directory"
DependsOn ="[WindowsFeature]AspNet45"
}
# Create the new Website
xWebsite BakeryWebSite
{
Ensure ="Present"
Name =$WebSiteName
State ="Started"
PhysicalPath =$DestinationPath
DependsOn ="[File]WebContent"
}
}
}
# Create the MOF file using configuration parameters
FourthCoffeeWebSite-NodeName"TestVM" `
-WebSiteName"FourthCoffee"-SourcePath"C:\BakeryWebsite\"-DestinationPath"C:\inetpub\FourthCoffee"
# Make it happen - Copy the MOF files to appropriate nodes and invoke the configuration
Start-DscConfiguration-Path "$PSScriptRoot\FourthCoffeeWebsite"-Wait-Verbose-Force
# Delete the MOF files
del-Path"$PSScriptRoot\FourthCoffeeWebsite"-Recurse-Verbose
Note: Any resource that is not shipped as part of Windows, needs to be available in a module in PSModulePath and must be imported (using Import-DSCResource keyword) before it can be used in a configuration.
Feel free to leave your feedback in the comments section as well as use the Q&A section in the TechNet pages. You can also provide feedback here in the connect page
Happy Holidays and a Happy new Year !!!
Narayanan (Nana) Lakshmanan
Development Lead - PowerShell DSC