Adding additional resources to existing modules

Our DSC resource has been repopulated and it's ready for testing. But first, I'm going to add in an additional DSC resource for creating a new partition. We'll be adding this DSC resource into the DiskSize module that we created for the DiskResize resource.

Like in our previous example, we'll be using the New-xDscResource and New-xDscResourceProperty cmdlets to generate the resource. We'll call the new resource DiskPartition, and direct it to the already existing DiskSize module. Here’s how to execute and then re-import the module:

So now I save the file and re-import the module. Let's take a look at the DSC resources we've created:

PS C:\Windows\system32> Get-DscResource -Module DiskSize -Syntax

DiskPartition [String] #ResourceName

{

DiskNumber = [string]

DriveLetter = [string]

[DependsOn = [string[]]]

[Ensure = [string]{ Absent | Present }]

[PsDscRunAsCredential = [PSCredential]]

}

DiskResize [String] #ResourceName

{

DiskSize = [UInt64]

DriveLetter = [string]

[DependsOn = [string[]]]

[Ensure = [string]{ Absent | Present }]

[PsDscRunAsCredential = [PSCredential]]

}

Awesome! Now let's import the module. We’ll test the DiskResize resource first because we need to resize the C partition before we can create the new partition. We'll place this as the first step in our configuration.

We’ll generate a new .mof file for our test machine. Remember to copy the new module to the test system because we're still using push configuration. And now we execute, and check our partition size:

Finally, let's update our configuration with the new partition resource provider and push our configuration to the target server.

We have success!

We've managed to take our Windows PowerShell configuration script and create a DSC configuration from it. We've even added some things to our configuration that we didn't previously have in the script by creating some new DSC resources for it.

There's still plenty of cleanup that needs to be done with our configuration and resources, such as adding error handling and some parameterization so we can further automate our deployments. By now, though, you should have a better understanding of how you can use Desired State Configuration to create basic configurations for your environment.

~Will

Wow! What a week. Thanks, Will, for seven days of DSC greatness. This is some really cool stuff.