1
votes

I have powershell 4 and would like to install selective windows features for example only install File Server FS-FileServer and File Server Resource Manager FS-Resource-Manager.

[X] File and Storage Services FileAndStorage-Services Installed [X] File Server FS-FileServer Installed [X] File Server Resource Manager FS-Resource-Manager Installed

for this my sample code looks like this

Configuration JSwebDeploy2
{ 
   Import-DscResource -ModuleName PSDesiredStateConfiguration

    node "localhost"
    { 

         WindowsFeature FS-FileServer
         {
            Name = "FS-FileServer"
            Ensure = 'Present'

         }
          WindowsFeature FS-Resource-Manager
         {
            Name = "FS-Resource-Manager"
            Ensure = 'Present'

         }
    }
} 

JSwebDeploy2

Is this the correct way to go about doing with or is there a way to group all sub features together. I came across WindowsFeatureSet but that is only avaliable in Powershell 5.0 onward.

1
If you are going to get into Desired State Configuration I strongly recommend upgrading to the latest version of Windows Management Framework, which would move you to at least PowerShell 5. - TheMadTechnician

1 Answers

1
votes

You should use version 5 in general, as TheMadTechnician said, but you can group the features, in a way, by generating the config in a loop:

Configuration JSwebDeploy2
{ 
   Import-DscResource -ModuleName PSDesiredStateConfiguration

    node "localhost"
    { 

         @('FS-FileServer','FS-Resource-Manager').ForEach({

             WindowsFeature $_
             {
                Name = $_
                Ensure = 'Present'
             }
         }
    }
} 

JSwebDeploy2

Use your loop construct of choice, and likely you'd want to parameterize the config instead of hardcoding the array, maybe use -ConfigurationData etc., but the concept is the same: use looping and variables when you build/generate your config.

This is just a side note, but version 5 has way more features for debugging and testing configurations, including the Invoke-DscResource cmdlet; very useful.

But beware that WindowsFeatureSet is a Composite resource, which is not supported by that particular cmdlet.