Import-DSCResource

Import-DSCResource is a dynamic keyword, not a cmdlet, contrary to what the verb-noun format suggests. Being a dynamic function, it behaves slightly differently from what you'd expect. Its parameters are not positional, so you have to specify them in order for it to work. It does not exist outside the configuration block, so you can't call it from the PowerShell commandlet line in isolation. This makes discovery using the normal PowerShell tools hard; you can't run Get-Help or Get-Member on it, so you will have to rely on PowerShell documentation. There are only a few parameters for Import-DSCResource: Name, ModuleName, and ModuleVersion.

The Name parameter accepts the ClassName of the DSC resource or its full name. This is generally the name of the DSC resource that is listed when running Get-DSCResource. You can specify one or more values to this parameter. It is preferred to use ModuleName because when Name is provided, DSC has to iterate over every DSC resource in the module path and search for the resource specified. This is a costly operation that has to happen for each name specified. It will also load the first matching resource, which means if there are different versions, the first one wins and it will miss the other versions. Another option is to use both ModuleName and Name when you want to specify that only one DSC resource is being used in a specific module. While this may not speed up resolution, it may be clearer to someone coming back to your DSC configuration script as to what exactly is being used.

The ModuleName parameter accepts the name of the module containing the DSC resources to be used. This parameter also accepts one or more string values of names to search for, but it also accepts hash tables. The hash table can specify both the name of the module and the version of the module to find. This ensures the correct version is used for your deployment. The flexibility and power of this parameter are coupled with the fact that it is more efficient than the Name parameter at finding and parsing the DSC resource specified in the module path.

The ModuleVersion parameter is used in WMF 5 and higher to indicate which version of a DSC resource to use. This parameter allows you to be specific about which version your DSC configuration will use. You would most likely use this parameter to pin your DSC configuration to a certain version of a DSC resource in order to ensure that you are not broken by new updates or parameter changes. If you are using WMF 4, then you would use the ModuleName parameter, as described earlier.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset