PowerShell Desired State Configuration (DSC) Journey – Day 15

Yesterday I explored the Archive Resource.  Today I am going to look at the Role Resource.  When you look at Get-DSCResource it isn’t called Role.  It’s called WindowsFeature.  Make complete sense right?  Here are the expanded properties.

Name                                            PropertyType                                                                        IsMandatory Values                                         
----                                            ------------                                                                        ----------- ------                                         
Name                                            [string]                                                                                   True {}                                             
Credential                                      [PSCredential]                                                                            False {}                                             
DependsOn                                       [string[]]                                                                                False {}                                             
Ensure                                          [string]                                                                                  False {Absent, Present}                              
IncludeAllSubFeature                            [bool]                                                                                    False {}                                             
LogPath                                         [string]                                                                                  False {}                                             
Source                                          [string]                                                                                  False {}

Alright.  Let’s do this.  You can find plenty of examples where people have installed one or two features using DSC.  Am I going to do that?  Absolutely not.  Let’s put this thing to the test.  To get a list of all the Windows Features available to install run this command.

Get-WindowsFeature -ComputerName ServerName

Alright.  Let’s try to break some stuff.  Here is all the code that I added to my ServerConfig Configuration.  I immediately want to see if I can include multiple names in one Resource block.  I am also trying to break the LogPath Property.  It says to specify a path to a log file, so I am including a log file name in here so we will see what happens with that.

        WindowsFeature MyServerFeatures
        {
            Name = "RSAT-SNMP,Remote-Assistance,BranchCache,PowerShellRoot"
            Ensure = "Present"
            IncludeAllSubFeature = $True
            LogPath = "C:\Scripts\MyServerFeatures.txt"

        }

The Consistency scheduled task on DSCTest didn’t run nearly long enough for this to have worked.  Let’s go to the log and see what I broke.

Trace-cDscOperation -ComputerName dsctest-01 -SequenceID 1 | Select-Object -ExpandProperty Message

And.  This is taking a long time to return anything.  That’s usually a sign that DSC itself is doing something.  Nope.  It came back right as I finished typing that.  Of course :).

This event indicates that failure happens when LCM is trying to get the configuration from pull server using download manager WebDownloadManager. ErrorId is 0x1. ErrorDetail is The SendConfig
urationApply function did not succeed.
DSC Engine Error : 
	 Error Message The SendConfigurationApply function did not succeed. 
	Error Code : 1 
This event indicates that failure happens when LCM is processing the configuration. ErrorId is 0x1. ErrorDetail is The SendConfigurationApply function did not succeed.. ResourceId is [Windows
Feature]MyServerFeatures and SourceInfo is C:\Users\jacob.benson\SkyDrive\PowerShell\DSC\ServerConfig.ps1::112::9::WindowsFeature. ErrorMessage is PowerShell provider MSFT_RoleResource  faile
d to execute Test-TargetResource functionality with error message: The requested feature RSAT-SNMP,Remote-Assistance,BranchCache,PowerShellRoot is not found on the target machine. .
Deleting file from C:\Windows\System32\Configuration\Pending.mof

Alright, it clearly didn’t like my Feature Names.  Let’s change the formatting a bit and try again.

Name = "RSAT-SNMP","Remote-Assistance","BranchCache","PowerShellRoot"

It likes that even less (which completely makes sense, but I had to check!).  Here is the error.

Write-NodeMOFFile : Invalid MOF definition for node 'DSCTEST-01.NFM.COM': Exception calling "ValidateInstanceText" with "1" argument(s): "Convert property 'Name' value from type 
'STRING[]' to type 'STRING' failed
 At line:165, char:2
 Buffer:
leVersion = "1.0";
};^
ins
"
At C:\windows\system32\windowspowershell\v1.0\Modules\PSDesiredStateConfiguration\PSDesiredStateConfiguration.psm1:1425 char:17
+                 Write-NodeMOFFile $name $mofNode $Script:NodeInstanceAliases[$mo ...
+                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: (:) [Write-Error], InvalidOperationException
    + FullyQualifiedErrorId : InvalidMOFDefinition,Write-NodeMOFFile

Alright, let’s try this instead.

            Name = "RSAT-SNMP"
            Name = "Remote-Assistance"

PowerShell ISE right away gives the second Name definition a squiggly which if you mouse over it plainly tells you that “Duplicate property resource definitions are not allowed in an instance definition”.  Well that certainly solves that.  Here is my new Configuration.

        WindowsFeature RSAT
        {
            Name = "RSAT-Role-Tools"
            Ensure = "Present"
            IncludeAllSubFeature = $True
            LogPath = "C:\Scripts\RSATFeatures.txt"

        }

        WindowsFeature PowerShell
        {
            Name = "PowerShellRoot"
            Ensure = "Present"
            IncludeAllSubFeature = $True
            LogPath = "C:\Scripts\PowerShellFeatures.txt"

        }

        WindowsFeature IISManagementTools
        {
            Name = "Web-Mgmt-Tools"
            Ensure = "Absent"
            IncludeAllSubFeature = $True
            LogPath = "C:\Scripts\IISMgmtToolsFeatures.txt"

        }

And the scheduled task is running.  While it is doing that, I am going to work on something else.  I imagine that’s going to take a while.

Checking back, I don’t see any of my Roles installed, but when I open the Add Roles and Features wizard it plainly tells me that the server has a pending restart.  Good sign!  I also check the C:\Scripts folder and see all of my specified text files in there, and it does look like everything ran.  Exciting stuff.

dsc26Time to reboot the server!  After the reboot, looking at the LocalConfigurationManager on DSCTest, it is set to reboot if needed, I wonder why it didn’t do that.  Or if I just didn’t wait long enough for it to reboot?  Either way, all the things got installed.

Now let’s install some IIS Management Tools and see if DSC will remove them.

Add-WindowsFeature -ComputerName servername.domain.com -Name "Web-Mgmt-Console" -LogPath C:\Scripts\WebConsole.txt
Success Restart Needed Exit Code      Feature Result                               
------- -------------- ---------      --------------                               
True    No             Success        {IIS Management Console, Management Tools,...

I double check using Get-WindowsFeature and it is installed.  So let’s run our scheduled task and see if it gets removed.

Before:

[X] Management Tools                                Web-Mgmt-Tools                 Installed
[X] IIS Management Console                      Web-Mgmt-Console               Installed

After:

[ ] Management Tools                                Web-Mgmt-Tools                 Available
[ ] IIS Management Console                      Web-Mgmt-Console               Available

If you are curious here is what my log file looks like when the IIS Management Tools were removed.

1760: 2014-03-27 14:47:54.926 [ServerManagerPS]           Complete initializing log file.
1760: 2014-03-27 14:47:54.926 [ServerManagerPS]           0c73a939-c0b0-496a-b087-178445f4dd1b Enumerate server component started. Component names: Web-Mgmt-Tools
1760: 2014-03-27 14:47:54.941 [ServerManagerPS]           0c73a939-c0b0-496a-b087-178445f4dd1b Enumerate server component ended with InProgress. The progress is 21.
1760: 2014-03-27 14:47:55.969 [ServerManagerPS]           0c73a939-c0b0-496a-b087-178445f4dd1b Get enumeration state ended with InProgress. The progress is 57.
1760: 2014-03-27 14:47:56.976 [ServerManagerPS]           0c73a939-c0b0-496a-b087-178445f4dd1b Get enumeration state ended with InProgress. The progress is 92.
1760: 2014-03-27 14:47:57.979 [ServerManagerPS]           0c73a939-c0b0-496a-b087-178445f4dd1b Get enumeration state ended with InProgress. The progress is 92.
1760: 2014-03-27 14:48:00.328 [ServerManagerPS]           0c73a939-c0b0-496a-b087-178445f4dd1b Get enumeration state ended with Completed.

1760: 2014-03-27 14:48:00.328 [ServerManagerPS]           Complete initializing log file.
1760: 2014-03-27 14:48:00.328 [ServerManagerPS]           1c9cab0e-4dea-459c-b116-1c658ca0391b Enumerate server component started. Component names: Web-Mgmt-Console
1760: 2014-03-27 14:48:00.594 [ServerManagerPS]           1c9cab0e-4dea-459c-b116-1c658ca0391b Enumerate server component ended with Success.

1760: 2014-03-27 14:48:00.625 [ServerManagerPS]           Complete initializing log file.
1760: 2014-03-27 14:48:01.500 [ServerManagerPS]           511f1a0d-a53b-4501-9e44-38c6a613cac0 Enumerate server component ended with Success.

1760: 2014-03-27 14:55:32.243 [ServerManagerPS]           Complete initializing log file.
1760: 2014-03-27 14:55:32.243 [ServerManagerPS]           7f1b990f-7950-470f-825d-91343ed04d02 Enumerate server component started. Component names: Web-Mgmt-Tools
1760: 2014-03-27 14:55:32.275 [ServerManagerPS]           7f1b990f-7950-470f-825d-91343ed04d02 Enumerate server component ended with InProgress. The progress is 21.
1760: 2014-03-27 14:55:33.294 [ServerManagerPS]           7f1b990f-7950-470f-825d-91343ed04d02 Get enumeration state ended with InProgress. The progress is 57.
1760: 2014-03-27 14:55:34.310 [ServerManagerPS]           7f1b990f-7950-470f-825d-91343ed04d02 Get enumeration state ended with InProgress. The progress is 92.
1760: 2014-03-27 14:55:35.317 [ServerManagerPS]           7f1b990f-7950-470f-825d-91343ed04d02 Get enumeration state ended with InProgress. The progress is 92.
1760: 2014-03-27 14:55:36.620 [ServerManagerPS]           7f1b990f-7950-470f-825d-91343ed04d02 Get enumeration state ended with Completed.

1760: 2014-03-27 14:55:36.636 [ServerManagerPS]           Complete initializing log file.
1760: 2014-03-27 14:55:36.933 [ServerManagerPS]           e14cb45d-d0a0-403c-b430-052f5440e747 Enumerate server component ended with Success.
1760: 2014-03-27 14:55:39.101 [ServerManagerPS]           e14cb45d-d0a0-403c-b430-052f5440e747 Alter server component started. Component names: Web-Mgmt-Tools,Web-Mgmt-Console,Web-Server
1760: 2014-03-27 14:55:39.118 [ServerManagerPS]           e14cb45d-d0a0-403c-b430-052f5440e747 Alter server component ended with InProgress. The progress is 20
1760: 2014-03-27 14:55:40.127 [ServerManagerPS]           e14cb45d-d0a0-403c-b430-052f5440e747 Alter server component started. Component names: Web-Mgmt-Tools,Web-Mgmt-Console,Web-Server
1760: 2014-03-27 14:55:40.143 [ServerManagerPS]           e14cb45d-d0a0-403c-b430-052f5440e747 Get alteration state ended with InProgress. The progress is 24.
1760: 2014-03-27 14:55:41.158 [ServerManagerPS]           e14cb45d-d0a0-403c-b430-052f5440e747 Alter server component started. Component names: Web-Mgmt-Tools,Web-Mgmt-Console,Web-Server
1760: 2014-03-27 14:55:41.190 [ServerManagerPS]           e14cb45d-d0a0-403c-b430-052f5440e747 Get alteration state ended with InProgress. The progress is 32.
1760: 2014-03-27 14:55:42.205 [ServerManagerPS]           e14cb45d-d0a0-403c-b430-052f5440e747 Alter server component started. Component names: Web-Mgmt-Tools,Web-Mgmt-Console,Web-Server
1760: 2014-03-27 14:55:42.221 [ServerManagerPS]           e14cb45d-d0a0-403c-b430-052f5440e747 Get alteration state ended with InProgress. The progress is 44.
1760: 2014-03-27 14:55:43.237 [ServerManagerPS]           e14cb45d-d0a0-403c-b430-052f5440e747 Alter server component started. Component names: Web-Mgmt-Tools,Web-Mgmt-Console,Web-Server
1760: 2014-03-27 14:55:43.283 [ServerManagerPS]           e14cb45d-d0a0-403c-b430-052f5440e747 Get alteration state ended with InProgress. The progress is 49.
1760: 2014-03-27 14:55:44.299 [ServerManagerPS]           e14cb45d-d0a0-403c-b430-052f5440e747 Alter server component started. Component names: Web-Mgmt-Tools,Web-Mgmt-Console,Web-Server
1760: 2014-03-27 14:55:44.330 [ServerManagerPS]           e14cb45d-d0a0-403c-b430-052f5440e747 Get alteration state ended with InProgress. The progress is 56.
1760: 2014-03-27 14:55:45.346 [ServerManagerPS]           e14cb45d-d0a0-403c-b430-052f5440e747 Alter server component started. Component names: Web-Mgmt-Tools,Web-Mgmt-Console,Web-Server
1760: 2014-03-27 14:55:45.362 [ServerManagerPS]           e14cb45d-d0a0-403c-b430-052f5440e747 Get alteration state ended with InProgress. The progress is 57.
1760: 2014-03-27 14:55:46.377 [ServerManagerPS]           e14cb45d-d0a0-403c-b430-052f5440e747 Alter server component started. Component names: Web-Mgmt-Tools,Web-Mgmt-Console,Web-Server
1760: 2014-03-27 14:55:46.752 [ServerManagerPS]           e14cb45d-d0a0-403c-b430-052f5440e747 Get alteration state ended with InProgress. The progress is 90.
1760: 2014-03-27 14:55:47.761 [ServerManagerPS]           e14cb45d-d0a0-403c-b430-052f5440e747 Alter server component started. Component names: Web-Mgmt-Tools,Web-Mgmt-Console,Web-Server
1760: 2014-03-27 14:55:47.761 [ServerManagerPS]           e14cb45d-d0a0-403c-b430-052f5440e747 Get alteration state ended with InProgress. The progress is 90.
1760: 2014-03-27 14:55:48.769 [ServerManagerPS]           e14cb45d-d0a0-403c-b430-052f5440e747 Alter server component started. Component names: Web-Mgmt-Tools,Web-Mgmt-Console,Web-Server
1760: 2014-03-27 14:55:48.769 [ServerManagerPS]           e14cb45d-d0a0-403c-b430-052f5440e747 Get alteration state ended with InProgress. The progress is 90.
1760: 2014-03-27 14:55:49.790 [ServerManagerPS]           e14cb45d-d0a0-403c-b430-052f5440e747 Alter server component started. Component names: Web-Mgmt-Tools,Web-Mgmt-Console,Web-Server
1760: 2014-03-27 14:55:49.790 [ServerManagerPS]           e14cb45d-d0a0-403c-b430-052f5440e747 Get alteration state ended with InProgress. The progress is 90.
1760: 2014-03-27 14:55:50.806 [ServerManagerPS]           e14cb45d-d0a0-403c-b430-052f5440e747 Alter server component started. Component names: Web-Mgmt-Tools,Web-Mgmt-Console,Web-Server
1760: 2014-03-27 14:55:50.806 [ServerManagerPS]           e14cb45d-d0a0-403c-b430-052f5440e747 Get alteration state ended with InProgress. The progress is 91.
1760: 2014-03-27 14:55:51.821 [ServerManagerPS]           e14cb45d-d0a0-403c-b430-052f5440e747 Alter server component started. Component names: Web-Mgmt-Tools,Web-Mgmt-Console,Web-Server
1760: 2014-03-27 14:55:51.837 [ServerManagerPS]           e14cb45d-d0a0-403c-b430-052f5440e747 Get alteration state ended with InProgress. The progress is 91.
1760: 2014-03-27 14:55:52.853 [ServerManagerPS]           e14cb45d-d0a0-403c-b430-052f5440e747 Alter server component started. Component names: Web-Mgmt-Tools,Web-Mgmt-Console,Web-Server
1760: 2014-03-27 14:55:52.868 [ServerManagerPS]           e14cb45d-d0a0-403c-b430-052f5440e747 Get alteration state ended with InProgress. The progress is 91.
1760: 2014-03-27 14:55:53.884 [ServerManagerPS]           e14cb45d-d0a0-403c-b430-052f5440e747 Alter server component started. Component names: Web-Mgmt-Tools,Web-Mgmt-Console,Web-Server
1760: 2014-03-27 14:55:53.884 [ServerManagerPS]           e14cb45d-d0a0-403c-b430-052f5440e747 Get alteration state ended with InProgress. The progress is 91.
1760: 2014-03-27 14:55:54.890 [ServerManagerPS]           e14cb45d-d0a0-403c-b430-052f5440e747 Alter server component started. Component names: Web-Mgmt-Tools,Web-Mgmt-Console,Web-Server
1760: 2014-03-27 14:55:54.890 [ServerManagerPS]           e14cb45d-d0a0-403c-b430-052f5440e747 Get alteration state ended with InProgress. The progress is 91.
1760: 2014-03-27 14:55:55.906 [ServerManagerPS]           e14cb45d-d0a0-403c-b430-052f5440e747 Alter server component started. Component names: Web-Mgmt-Tools,Web-Mgmt-Console,Web-Server
1760: 2014-03-27 14:55:56.469 [ServerManagerPS]           e14cb45d-d0a0-403c-b430-052f5440e747 Get alteration state ended with InProgress. The progress is 91.
1760: 2014-03-27 14:55:57.484 [ServerManagerPS]           e14cb45d-d0a0-403c-b430-052f5440e747 Alter server component started. Component names: Web-Mgmt-Tools,Web-Mgmt-Console,Web-Server
1760: 2014-03-27 14:55:57.484 [ServerManagerPS]           e14cb45d-d0a0-403c-b430-052f5440e747 Get alteration state ended with Completed.

I am off tomorrow but I will pick back up next week.  I think it’s time for some more Custom Resources.  Hyper-V Anyone?