jsmickey
jsmickey

Reputation: 738

Add IIS 8.5 Custom Logging Fields with Powershell

Windows Server 2012 R2 with IIS 8.5 allows for custom log fields with Enhanced Logging

http://www.iis.net/learn/get-started/whats-new-in-iis-85/enhanced-logging-for-iis85

I want to add the fields with Powershell

The following works:

Set-ItemProperty IIS:\Sites\siteName -name logfile.customFields.collection -value
 @{logFieldName='foo';sourceType='RequestHeader';sourceName='c-ip'}

But I cannot add a second entry to logfile.customFields.collection It requests -Force and overwrites the existing entry

I added 2 via the GUI to illustrate the issue

Get-ItemProperty IIS:\Sites\siteName -name logfile.customFields.collection

logFieldName   : foo
sourceName     : c-ip
sourceType     : RequestHeader
Attributes     : {logFieldName, sourceName, sourceType}
ChildElements  : {}
ElementTagName : add
Methods        :
Schema         : Microsoft.IIs.PowerShell.Framework.ConfigurationElementSchema

logFieldName   : foo2
sourceName     : c-servername
sourceType     : RequestHeader
Attributes     : {logFieldName, sourceName, sourceType}
ChildElements  : {}
ElementTagName : add
Methods        :
Schema         : Microsoft.IIs.PowerShell.Framework.ConfigurationElementSchema

logFieldName, sourceName, and sourceType are NoteProperty Members with the same name

How do I do this in Powershell?

Upvotes: 4

Views: 3728

Answers (1)

jsmickey
jsmickey

Reputation: 738

A user on the IIS Forums answered

   New-ItemProperty IIS:\Sites\siteName -name logfile.customFields.collection -value
         @{logFieldName='foo';sourceType='RequestHeader';sourceName='c-ip'}

   New-ItemProperty IIS:\Sites\siteName -name logfile.customFields.collection -value
         @{logFieldName='foo2';sourceType='RequestHeader';sourceName='c-ip'}

I confirmed this does work

Upvotes: 6

Related Questions