none
How to add more than one role and feature using PowerShell Desired State Configuration RRS feed

  • Question

  • Hi all.

    I am working with 2012 R2 and have WMF 5 installed and can happily PUSH config to servers using PS DSC. Here is my little script that I use to create the config file.

    Configuration TestWebPush

    {

    node $computername

    {

    WindowsFeature IIS

        {

    Ensure = "Present"
    Name = "Web-Server"

        }

       }

      }

    TestWebPush
    $ComputerName = "srv01", "srv02"

    This works just fine but here is my question. How can I add a second Role? I have tried "role1,role"  and then under "NAME" put down "feature1", "feature2"   but I get errors. I haven't loaded the error here because I am hoping something will look at the script and just advise how I add a 2nd role and point out my mistake.

    Thanks all.




    • Edited by Palmer_001 Sunday, January 22, 2017 3:37 PM
    Sunday, January 22, 2017 3:35 PM

Answers

  • Hi,

    >>Would you mind explaining that if possible? 

    Of course.

    >>how do you add to the script any of the many features that are available for that role or perhaps you can't add features?

    Using -IncludeAllSubFeature parameter.

    https://msdn.microsoft.com/en-us/powershell/dsc/windowsfeatureResource?f=255&MSPPError=-2147217396

    >>And one last thing if I may, I can make out what the "Node $MachineName" is in your script but not what or where the "param

    I just use this to define a variable for node so you could assign a value for your Node , nothing else!

    If you know how to write powershell module, you'll know much more.

    Best regards,

    Andy


    Please remember to mark the replies as answers if they help.
    If you have feedback for TechNet Subscriber Support, contact tnmff@microsoft.com.

    • Marked as answer by Palmer_001 Tuesday, January 24, 2017 7:37 AM
    Tuesday, January 24, 2017 2:06 AM
    Moderator

All replies

  • Hi,

    Here is an example:

    Configuration ContosoWebsite 
    { 
      param ($MachineName)
    
      Node $MachineName 
      { 
        #Install the IIS Role 
        WindowsFeature IIS 
        { 
          Ensure = “Present” 
          Name = “Web-Server” 
        } 
    
        #Install ASP.NET 4.5 
        WindowsFeature ASP 
        { 
          Ensure = “Present” 
          Name = “Web-Asp-Net45” 
        } 
      } 
    } 
     
    

    Best regards

    Andy


    Please remember to mark the replies as answers if they help.
    If you have feedback for TechNet Subscriber Support, contact tnmff@microsoft.com.

    Monday, January 23, 2017 6:09 AM
    Moderator
  • Hi,

    Here is an example:

    Configuration ContosoWebsite 
    { 
      param ($MachineName)
    
      Node $MachineName 
      { 
        #Install the IIS Role 
        WindowsFeature IIS 
        { 
          Ensure = “Present” 
          Name = “Web-Server” 
        } 
    
        #Install ASP.NET 4.5 
        WindowsFeature ASP 
        { 
          Ensure = “Present” 
          Name = “Web-Asp-Net45” 
        } 
      } 
    } 
     

    Best regards

    Andy


    Please remember to mark the replies as answers if they help.
    If you have feedback for TechNet Subscriber Support, contact tnmff@microsoft.com.

    Hi Andy, thank you, can I ask if I am reading this correctly. So IIS is the role and Web-Server is a feature of that role,  is that how it works because I was wondering when for example you add the IIS role, how do you add to the script any of the many features that are available for that role or perhaps you can't add features?  And one last thing if I may, I can make out what the "Node $MachineName" is in your script but not what or where the "param ($MachineName)" comes into play. Would you mind explaining that if possible?  Thank you.
    Monday, January 23, 2017 11:36 PM
  • Hi,

    >>Would you mind explaining that if possible? 

    Of course.

    >>how do you add to the script any of the many features that are available for that role or perhaps you can't add features?

    Using -IncludeAllSubFeature parameter.

    https://msdn.microsoft.com/en-us/powershell/dsc/windowsfeatureResource?f=255&MSPPError=-2147217396

    >>And one last thing if I may, I can make out what the "Node $MachineName" is in your script but not what or where the "param

    I just use this to define a variable for node so you could assign a value for your Node , nothing else!

    If you know how to write powershell module, you'll know much more.

    Best regards,

    Andy


    Please remember to mark the replies as answers if they help.
    If you have feedback for TechNet Subscriber Support, contact tnmff@microsoft.com.

    • Marked as answer by Palmer_001 Tuesday, January 24, 2017 7:37 AM
    Tuesday, January 24, 2017 2:06 AM
    Moderator