Edit XML file using DSC

This topic contains 5 replies, has 4 voices, and was last updated by Profile photo of Aravinda Cat Aravinda Cat 9 months, 2 weeks ago.

  • Author
    Posts
  • #21839
    Profile photo of Aravinda Cat
    Aravinda Cat
    Participant

    Hi All,

    I am working on a server setup using DSC. Intial setup for IIS needs the ApplicationHost.config file to be edited and modified. As this is a XML file, can we modify the tags of this file using any of the DSC module available?

    If there is no module available for this task, Please guide me to create a custom module to complete this.

    Thanks

  • #21851
    Profile photo of Don Jones
    Don Jones
    Keymaster

    I'm not aware of an existing XML-editing resource. You would need to build something custom, if that was the goal. "The DSC Book" has an overview of creating custom resource modules, and our DSC Hub links to our Git repo, where you can find several custom modules to use as examples.

  • #21854
    Profile photo of Dave Wyatt
    Dave Wyatt
    Moderator

    The WebAdministration module has several commands for managing IIS configuration files, without having to concern yourself with the XML directly. (Get-Command -Module WebAdministration -Name *config*). The DSC resource kit's xWebAdministration module has a resource called xWebConfigKeyValue which might be what you're looking for; it uses these WebAdministration commands to manage the files.

    Note: For some reason, the "Wave 9" download of the DSC resource kit is missing some of the xWebAdministration resources, including xWebConfigKeyValue. It's present in the Wave 8 download, though.

  • #21913
    Profile photo of Aravinda Cat
    Aravinda Cat
    Participant

    Hi Dave,

    Checked the xWebConfigKeyValue resource and it is configured to modify the Appsettings of the web.config file of the WebSite. As per my requirement , I need to modify the logfile path of the applicationhost.config file. Already the powershell script to do the job is as below :

    Set-WebConfigurationProperty '/system.applicationHost/sites/siteDefaults/logfile' -PSPath IIS:\ -Name directory -Value $logsPath

    Can I modify the below parameters to run the above command?

    xWebConfigKeyValue RecaptchaPublicKey
    {
    WebsitePath =[s] $managementPortalInstallPath[/s]
    ConfigSection = 'AppSettings'
    Key =[s] 'recaptchaPublicKey'[/s]
    Value =[s] $Node.RecaptchaPublicKey[/s]
    DependsOn = [s]'[File]ManagementPortalContents'[/s]
    }

  • #35432
    Profile photo of Jakob Sjögren
    Jakob Sjögren
    Participant

    With this module: https://github.com/PowerShell/xWebAdministration there is a setting you can use.
    eg.
    xWebSiteDefaults IIS
    {
    ApplyTo = 'Machine'
    LogFormat = 'W3C'
    AllowSubDirConfig = $true
    LogDirectory = 'E:\LogFiles\IISLogs'
    DependsOn = "[WindowsFeature]IIS"
    }

  • #35462
    Profile photo of Aravinda Cat
    Aravinda Cat
    Participant

    Thanks Guys,

    It is already done and we can mark this completed.
    Working fine across all of my shared environment.

You must be logged in to reply to this topic.