Is there a scripted way to configure Failed Request Tracing (FRT) and FRT rules
I just needed the same and saw this unanswered question, then ended up creating a function for this with a simple use case of only adding status codes and time taken rules, but you can further extend it based on this sample.Note: it's my first draft, but wanted to share
https://github.com/cjharmath/iisseven/blob/master/Enable-IISTracing.ps1
In case things change, let me paste some example here as well
Step 1) Enable IIS Failed Request Tracing on the site
$psPath = "IIS:\Sites\$SiteName"Set-ItemProperty -PsPath $psPath -Name traceFailedRequestsLogging ` -Value @{ enabled = $true directory = "%SystemDrive%\inetpub\logs\FailedReqLogFiles" maxLogFiles = 100}
Step 2) Optionally clear existing policies
$pspath = "MACHINE/WEBROOT/APPHOST/$SiteName"Clear-WebConfiguration "/system.webServer/tracing/traceFailedRequests" -PSPath $pspath
Step 3) Add properties one by one with Add-WebConfigurationProperty and Set-WebConfigurationProperty
Add-WebConfigurationProperty -pspath $pspath ` -filter "system.webServer/tracing/traceFailedRequests" -name "." -value @{path = "$Path"}Add-WebConfigurationProperty -pspath $pspath ` -filter "system.webServer/tracing/traceFailedRequests/add[@path='$Path']/traceAreas" -name "." ` -value @{provider = 'ASPNET'; areas = 'Infrastructure,Module,Page,AppServices'; verbosity = 'Verbose'}Set-WebConfigurationProperty -pspath $pspath ` -filter "system.webServer/tracing/traceFailedRequests/add[@path='$Path']/failureDefinitions" `-name "statusCodes" -value $FailureStatusCodes