Modify Http-Logging feature using DSC

Hi All,

I am working on a server configuration where the default logpath for the default web site needs to be changed to a custom path using DSC.
Here is the code snippet in DSC .

WindowsFeature HttpLogging
  {
    Ensure = "Present"
    Name = "Web-Http-Logging"
    LogPath = $logspath //custom path
  }

Here is the error while running the Start-DSCConfiguration command.

[b]WriteError: Failed to write the log file: D:\SystemData\logs. Please specify a file name.
+ CategoryInfo : OperationStopped: [D:\SystemData\logs:] , CimException
+ FullyQualifiedErrorId : InitializeLogFileFailed,Microsoft.Windows.ServerManager.Commands.GetWindowsFeatureCommand
+ PSComputerName : ARWW2K12T01.mw.na.cat.com[/b]

Please let me know your thoughts on this and how to proceed differently if required.

Thanks,
Aravinda

The LogPath wants a filename, not just a path.

What you’re describing (changing the log path for a website) isn’t something you’d do with the WindowsFeature DSC resource. The LogPath property on that resource just specifies where to put a log file of the operation of installing or removing a windows feature; it doesn’t do anything related to a website in IIS (other that possibly installing the IIS feature ahead of time so you can set up a website.)

You probably want to be looking into the xWebAdministration module of the DSC resource kit (or possibly the community version, cWebAdministration, depending on your needs.) It has DSC resources such as xWebsite and xWebConfigKeyValue, which might meet your needs.

I actually did this using the Script resource. I’m new to DSC, so this isn’t ideal, but you should get the idea.

#Set default logging location
Script DefaultLogging
{
    SetScript =
    {
        Set-WebConfigurationProperty -Filter '/system.applicationHost/sites/siteDefaults' -Name logFile.directory -Value "D:\LogFiles"
    }
    TestScript =
    {
        (Get-WebConfigurationProperty -Filter '/system.applicationHost/sites/siteDefaults' -Name logFile.directory | select -ExpandProperty value) -eq "D:\LogFiles"
    }
    GetScript =
    {
        $returnvalue = @{
            Ensure = if ((Get-WebConfigurationProperty -Filter '/system.applicationHost/sites/siteDefaults' -Name logFile.directory | select -ExpandProperty value) -eq "D:\LogFiles"){
                "Present"
            } else {
                "Absent"
            }
        }
        $returnvalue
    }
}

Hi All,

Thanks for the help. After using the above code when I tried to run the mof file , in the destination server side I found the below details using Get-DSCConfiguration command.

Credential :
DisplayName : HTTP Logging
Ensure : Present
IncludeAllSubFeature : False
LogPath :
Name : Web-Http-Logging
Source :
PSComputerName :

Looking into this , we can easily say that there is a property called ‘LogPath’ is associated with the windowsfeature ‘Web-Http-Logging’. So, I want this path to be set. Below is the code written to set the path using powershell script.

Set-ItemProperty ‘IIS:\Sites\Default Web Site’ -name logFile.directory -value $logsPath //$logsPath = “D:\logs”

Thanks,
Aravinda

Hi Tom,

I use the script resource method to execute the task, but for Value if I provide a hardcoded path like D:\SystemData it works fine. If a parameter is passed for the value then I am getting below error.

PowerShell provider MSFT_ScriptResource failed to execute Set-TargetResource functionality with error message: Cannot bind argument to parameter ‘Value’ because it is null.
+ CategoryInfo : InvalidOperation: (:slight_smile: , CimException
+ FullyQualifiedErrorId : ProviderOperationExecutionFailure
+ PSComputerName : localhost

Any idea why it is not taking the parameter for value. HEre is the code :

Set-WebConfigurationProperty ‘/system.applicationHost/configHistory’ -PSPath IIS:\ -Name path -Value $configHistoryPath