How to change the IIS log contents with PowerShell

Ever want to change the type of information contained in your IIS logs?  While the default settings are useful, there’s much more data you could be collecting.  Graphical you can do this on a per server bases in the “Logging” feature and selecting the “Select Fields” option.

W3C Logging Fields How to change the IIS log contents with PowerShell

My problem is that I want to set this on several web servers. You can do this using PowerShell Remoting and the Set-WebConfigurationProperty cmdlet from the WebAdministration module.

To get a list of the current fields:

PS> $Session=New-PsSession –ComputerName Web1, Web2, Web3

PS> Invoke-Command –Session $Session {

Get-WebConfiguration –filter system.applicationhost/sites/sitedefaults/logfile |

Select-Object -ExpandProperty logExtFileFlags }

To change the list using the same Remoting session:

Invoke-Command –Session $session {

Set-WebConfigurationProperty -Filter System.Applicationhost/Sites/SiteDefaults/logfile -Name LogExtFileFlags -Value "Date,Time,ClientIP"}

Have fun!

Knowledge is PowerShell

Jason

 

Jason Helmick
Director of PowerShell Technologies
Interface Technical Training

Posted in PowerShell | Posted in , , , , , | Leave a comment

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code class="" title="" data-url=""> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre class="" title="" data-url=""> <span class="" title="" data-url="">