A DSC resource is a specially crafted PowerShell module that enables DSC to configure various aspects of a node. The WindowsFeature
DSC resource, for example, enables you to ensure that a particular node has a particular Windows feature installed. You can also specify that a particular Windows feature should not be present (in which case, DSC removes the feature if it were already installed).
As you saw in the Using DSC and built-in resources recipe, Microsoft does not ship very many DSC resources natively with Windows Server 2019. This is intentional—you use the PowerShell Gallery to get the DSC resources you need to do your job and not hundreds or thousands of DSC resources you never need.
The built-in DSC resources with Windows Server 2019 do not provide broad coverage, and are not sufficient for most organizations. For example, you can use the built-in File
resource to copy the source files for a small web application onto a new server, as you did in the Using DSC and built-in resources recipe. But the built-in resources do not allow you to specify the application's settings (what the application's name is, which application pool it runs in, and so on). This is where add-on DSC resources from the PS Gallery come in.
In this recipe, you use the PS Gallery to find, install, and explore third-party DSC resources. In the next recipe, Using DSC with resources from PS Gallery, you use the newly installed resources.
Get-PSRepository
Find-DscResource -Repository 'PSGallery' | Measure-Object
Find-DscResource | Where-Object ModuleName -match 'web|iis' | Select-Object -Property ModuleName, Version -Unique | Sort-Object -Property ModuleName
xWebAdministration
module using the following code:Find-DscResource -ModuleName 'xWebAdministration'
xWebAdministration
module (on SRV1
) using the following code:Install-Module -Name 'xWebAdministration' -Force
Get-Module -Name xWebAdministration -ListAvailable
Get-DscResource -Module xWebAdministration
$Mod = Get-Module -Name xWebAdministration -ListAvailable $P = $Mod.Path $FP = Split-Path -Parent $P Get-ChildItem -Path $FP, $FPDSCResources
In step 1, you examine any configured repositories on your system. Depending on the recipes you have performed on SRV1
, the output of this step looks like this:
In step 2, you use the Find-DSCResource
cmdlet to examine how many DSC resources are in the gallery (at the time of writing!), which looks like this:
In step 3, you query the PS Gallery to find DSC resources that might be helpful to manage IIS. The output looks like this:
In step 4, you look at the DSC resources in the xWebAdministration
module on the PS Gallery. The output looks like this:
In step 5, you install the module on SRV1
. This step produces no output. In step 6, you examine the details of the newly installed module, which looks like this:
In step 7, you use the Get-DscResource
cmdlet to discover the specific DSC resources contained in the xWebAdministration
module, which looks like this:
In the last step, step 8, you view the files that make up the xWebAdministration
module. The output looks like this:
This recipe describes how to obtain DSC resources from the PowerShell Gallery repository, but there are many other places that you can find DSC resources. One other repository you might consider is Chocolatey (https://www.chocolatey.org).
In step 3, you query the PS Gallery to discover DSC resources that might be useful. In this step, you find any DSC resource whose name contains either web
or iis
. Depending on what DSC resource you are looking for, you may need to adjust this regular expression string.
In step 8, you view the files that make up the xWebAdministration
module. To learn more about how to develop DSC resources, you should examine the files in this module in more detail.
In step 8, you examine the files making up the xWebAdministration
module. For more information about what is inside a DSC resource module, see https://docs.microsoft.com/en-us/powershell/dsc/resources/resources.
If you cannot find the DSC resources you need, you can always create your own customized resources. There are two main methods that IT pros can use to write their own resources. You can use the traditional approach, where you both write the PowerShell code and create a MOF schema. With PowerShell 5, Microsoft introduced a much simpler method of creating a DSC resource based on PowerShell classes. For more details about the older mechanism, see https://docs.microsoft.com/en-us/powershell/dsc/resources/authoringresourcemof, and for more details about creating a DSC resource using PowerShell classes, see https://docs.microsoft.com/en-us/powershell/dsc/resources/authoringresourceclass. And finally, for the hard core folks, you can implement the resource in C# (https://docs.microsoft.com/en-us/powershell/dsc/resources/authoringresourcemofcs).
If you do decide to develop your own DSC resources, take a look at using the Resource Designer tool—a set of cmdlets that make creating DSC resources easier. See https://docs.microsoft.com/en-us/powershell/dsc/resources/authoringresourcemofdesigner for more details about this tool.
3.135.182.107