IIS Advanced Logging - Scripting Out Filters via Powershell

1.1k views Asked by At

I am already scripting the majority of the IIS Advanced Logging setup via powershell.

Goal

I'd like to automate the <filters> section of the root server logDefinition. I've tried multiple commands, none seeming to work.

Ultimately, the system.webServer/advancedLogging/server/logDefinitions/logDefinition[@baseFileName='%COMPUTERNAME%-Server'] section should have some XML like this:

<filter>
    <condition operator="And">
        <condition operator="And">
            <expression field="URI-Stem" operator="NotEquals" value="/serverstatuscheck" caseSensitive="false" regularExpression="false" />
        </condition>
    </condition>
</filter>

Attempt 1

I tried the following 2 commands in powershell - they didn't give me any errors, but didn't have any effect either:

Add-WebConfiguration -Filter "system.webServer/advancedLogging/server/logDefinitions/logDefinition[@baseFileName='%COMPUTERNAME%-Server']/filter" -Value @{operator='And'}

And

Add-WebConfiguration -Filter "system.webServer/advancedLogging/server/logDefinitions/logDefinition[@baseFileName='%COMPUTERNAME%-Server']/filter" -Value @{elementTagName="condition";operator='And'}

Then I tried the following command, and got the error Add-WebConfiguration : Key value is missing. (though I am not sure which key it is looking for):

Add-WebConfiguration -Filter "system.webServer/advancedLogging/server/logDefinitions/logDefinition[@baseFileName='%COMPUTERNAME%-Server']/filter/condition" -Value @{operator='And'}

Attempt 2

My next attempt was to use the Configuration Editor to generate a script. So I went and made my changes, clicked Generate Script and pulled out the Powershell that it generated. Here is what that looks like:

Add-WebConfigurationProperty -pspath 'MACHINE/WEBROOT/APPHOST'  -filter "system.webServer/advancedLogging/server/logDefinitions/logDefinition[@baseFileName='%COMPUTERNAME%-Server']/filter/condition" -name "." -value @{}

Add-WebConfigurationProperty -pspath 'MACHINE/WEBROOT/APPHOST'  -filter "system.webServer/advancedLogging/server/logDefinitions/logDefinition[@baseFileName='%COMPUTERNAME%-Server']/filter/condition/condition[]" -name "." -value @{field='URI-Stem';operator='NotEquals';value='/serverstatuscheck'}

But that didn't work either. I got the same Add-WebConfiguration : Key value is missing. error as above.

My Question

Can anyone nudge me in the right direction? I feel like I am close, but have been hitting walls. I can manually configure this just fine.

Thanks in advance for any help!

1

There are 1 answers

1
darm On

After many tries, try this one:

Add-WebConfigurationProperty -Filter "/system.webServer/advancedLogging/server/logDefinitions/logDefinition[@baseFileName='%COMPUTERNAME%-Server']/filter/condition" -name "." -value @{field='URI-Stem';operator='NotEquals';value='/serverstatuscheck'}