Automating the world one-liner at a time…
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
Name a computer and add it to a domain/workgroup
Create and managed VHDs
Create and manage a Hyper-V Virtual Machine
Create and manage a Hyper-V Virtual Switch
Bind a DNS Server address to one or more NIC
Configure IPAddress (v4 and v6)
Configure DSC Service (aka Pull Server)
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 by replacing MSFT with your company/community name and replacing the “x” with "c" (short for "Community") or another prefix of your choice:
a. Module name (ex: xWebAdministration becomes cWebAdministration)
a. Folder name (ex: MSFT_xWebsite becomes Contoso_cWebsite)
b. Resource Name (ex: MSFT_xWebsite becomes Contoso_cWebsite)
c. Resource Friendly Name (ex: xWebsite becomes cWebsite)
d. MOF class name (ex: MSFT_xWebsite becomes Contoso_cWebsite)
e. Filename for the <resource>.schema.mof (ex: MSFT_xWebsite.schema.mof becomes Contoso_cWebsite.schema.mof)
2. Update module and metadata information in the module manifest
3. Update any configuration that use these resources
We reserve resource and module names without prefixes ("x" or "c") for future use (e.g. "MSFT_WebAdministration" or "Website"). If the next version of Windows Server ships with a "Website" resource, we don't want to break any configurations that use any community modifications. Please keep a prefix such as "c" on all community modifications.
As specified in the license, you may copy or modify this resource as long as they are used on the Windows Platform.
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):
# Target nodes to apply the configuration
# Name of the website to create
# Source Path for Website content
# Destination path for Website content
# Import custom resources from the module that defines it
Import-DscResource -Module xWebAdministration
# Install the IIS role
Ensure = "Present"
Name = "Web-Server"
# Install the ASP .NET 4.5 role
Name = "Web-Asp-Net45"
# Stop the default website
Name = "Default Web Site"
State = "Stopped"
PhysicalPath = "C:\inetpub\wwwroot"
DependsOn = "[WindowsFeature]IIS"
# Copy the website content
SourcePath = $SourcePath
DestinationPath = $DestinationPath
Recurse = $true
Type = "Directory"
DependsOn = "[WindowsFeature]AspNet45"
# Create the new Website
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 !!!
Updated on 1/2/2014: Updated the renaming guidelines with examples
Narayanan (Nana) Lakshmanan
Development Lead - PowerShell DSC
PS C:\projects\DSC-WorkInProgress> Import-DscResource -Module PowerShellAccessControl
Import-DscResource : The term 'Import-DscResource' is not recognized as the
name of a cmdlet, function, script file, or operable program. Check the
spelling of the name, or if a path was included, verify that the path is
correct and try again.
At line:1 char:1
+ Import-DscResource -Module PowerShellAccessControl
+ CategoryInfo : ObjectNotFound: (Import-DscResource:String) ,
+ FullyQualifiedErrorId : CommandNotFoundException
PS C:\projects\DSC-WorkInProgress> Get-HotFix |Where-Object -Property HotFixID -
Source Description HotFixID InstalledBy InstalledOn
------ ----------- -------- ----------- -----------
IT08082 Update KB2883200 it08082\Administr... 9/30/2013 ...
PS C:\projects\DSC-WorkInProgress> Get-Command -Module PSDesiredStateConfiguration |Select-Object -Property Name
This blog article (www.ashleypoole.co.uk/.../where-is-import-dscresource-in-powershell-dsc) mentioned that you need kb 2883200 before that command will show up, this does not appear to be the case. Can anyone figure this out?
While Import-DscResource looks like a cmdlet, it only works within a DSC Configuration. For more details, check out this blog post.
Does that help?
So, I, too was getting this error:
> The PowerShell provider * does not exist at the PowerShell module path nor is it registered as a WMI provider.
for one of my moduels on a server that previously was working and downloading stuff. Rebooting didn't work. Killing WMI processes didn't work. It turns out, I had changed a .mof file without updating its checksum. As soon as I updated my checksum, things started working again.
I have a fresh new Win 2K12 R2, with Feb 2015 preview installed and downloaded "DSC Resourc Kit Wave 10 182015.zip", AllResources directory put under C:\Program Files\WindowsPowerShell\Modules
I copied the example configuration provided to set up a new IIS website. 1st of all, I get a quiugly broken redline on xWebsite, indicating "Undefined DSC resource 'xWebsite'. Use Import-DSCResource to import the resource.
"Import-DscResource -Module xWebAdministration" is declared in the begining of the script, when I run the script I get
"The term 'Import-DscResource is not recognized as the name of a cmdlet.........."
I searched this site, followed, what I was able to understand that fix KB2883200 is is "InstalledOn = 3/24/2015", yesterday.
Issuing Get-Dsecresource, I can see clearly 2 modules, "xWebApplication and xWebVirtualDirectory".
Also, I discovered that Import-DscResource is not recognized neither on the commandline nor in the help in ISE
What can be missing? Thanks in advance
@eliassal: While Import-DscResource looks like a cmdlet, it only works within a DSC Configuration. For more details, check out this blog post.
@eliassal: I apologize. There's also currently a problem with the xWebAdministration module mismatched across TechNet and Gallery.. It will be fixed soon.
Effective immediately, we've fixed the missing resource problem in xWebAdministration 126.96.36.199. All missing files/directories should be back in all TechNet zip files and on the Gallery. Sorry for the confusion and the delay.
Re custom DSC resources and the following error:
I found something odd with this to do with the Machine level PSModulePath environment variable.
When "C:\Program Files\WindowsPowerShell\Modules" is IN that path, Get-DscResource works & running the configuration script to generate the .mof file works, but running Start-DscConfiguration fails with the above message.
When "C:\Program Files\WindowsPowerShell\Modules" is NOT IN that path, Get-DscResource can't find the resource, and running the configuration script fails, unable to import the module, however if the mof file has previously been generated, Start-DscConfiguration succeeds.
To workaround this, our build script is adding the path to PSModulePath for the first step, and removing it for the second.
We're looking into alternative ways to get the first step to succeed, so we never have to change the Machine level PSModulePath at all - but no luck yet.
Not sure if this quirk can shed any light on the root cause of why us and others are getting this error message.