How to change the IIS log contents with PowerShell

Home > Blogs > PowerShell > How to change the IIS log contents with PowerShell

How to change the IIS log contents with PowerShell

1 0 Jason Helmick
Added by March 1, 2013

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

Videos You May Like

A Simple Introduction to Cisco CML2

0 3850 0

Mark Jacob, Cisco Instructor, presents an introduction to Cisco Modeling Labs 2.0 or CML2.0, an upgrade to Cisco’s VIRL Personal Edition. Mark demonstrates Terminal Emulator access to console, as well as console access from within the CML2.0 product. Hello, I’m Mark Jacob, a Cisco Instructor and Network Instructor at Interface Technical Training. I’ve been using … Continue reading A Simple Introduction to Cisco CML2

Difference Between $_ and $PSItem in Windows PowerShell

2 1905 4

In this video, I’m going to answer a very common question that I get when I’m teaching Windows PowerShell, and that’s, “What’s the difference between what’s called $_ and $PSItem?” Let me explain to you a little bit about what these two variables do. When we’re working with the PowerShell pipeline, and we want to … Continue reading Difference Between $_ and $PSItem in Windows PowerShell

How to Build in a PSMethod to your PowerShell Code

0 72 0

In this video, PowerShell instructor Jason Yoder shows how to add Methods (PSMethod) to your code using free software that’s added into the PSObject. For instructor-led PowerShell courses, see our course schedule. Microsoft Windows PowerShell Training Download the Building Methods PowerShell script</a> used in this video. <# ╔══════════════════════════════════════════════════════════════════════════════╗ ║ ║ ║ Building Methods ║ ╟──────────────────────────────────────────────────────────────────────────────╢ … Continue reading How to Build in a PSMethod to your PowerShell Code

Write a Comment

Share your thoughts...

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