• Technologies

  • Instructors

  • 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 Helmick
    Director of PowerShell Technologies
    Interface Technical Training

    You may also like:  Using PowerShell to convert to the Full Graphical Shell on a Windows Server 2012 R2 Datacenter Core Edition.

    Share your thoughts...

    Please fill out the comment form below to post a reply.