Powershell command to enable logging fields in the log definition of IIS Advanced logging

797 views Asked by At

I am looking for a powershell script to enable the field in one of the logging definitions in IIS advanced logging.

See screenshot as below.

Enable Fields in log definition of IIS advanced logging

I tried the following command.

Set-WebConfigurationProperty -Filter "system.webServer/advancedLogging/Server/logDefinitions/[@baseFileName='%COMPUTERNAME%-Server']/selectedFields" -PSPath machine/webroot/apphost -Name VIP_Name -value "True"

I get the following error

Set-WebConfigurationProperty : Unexpected token Input: get-config("MACHINE/WEBROOT/APPHOST")/system.webServer/advancedLogging/Server/log Definitions/[@baseFileName='%COMPUTERNAME%-Server']/Fields Position: 93 Length: 1 Fragment: [ At D:\AdvanceLogging.ps1:10 char:1 + Set-WebConfigurationProperty -Filter "system.webServer/advancedLoggin ... + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : NotSpecified: (:) [Set-WebConfigurationProperty], Argumen tException + FullyQualifiedErrorId : System.ArgumentException,Microsoft.IIs.PowerShell.Provide
r.SetConfigurationPropertyCommand

I dont know if the above command is the right one, can someone please help ?

1

There are 1 answers

0
Jokies Ding On BEST ANSWER

If you wanna add that filter in server node Please try this.

Add-WebConfigurationProperty -pspath 'MACHINE/WEBROOT/APPHOST'  -filter "system.webServer/advancedLogging/server/logDefinitions/logDefinition[@baseFileName='%COMPUTERNAME%-Server']/selectedFields" -name "." -value @{id='VIP_Name';logHeaderName='VIP_Name'}

If you want to set filter in site level, Please use this command.

Add-WebConfigurationProperty -pspath 'MACHINE/WEBROOT/APPHOST' -location 'Default Web Site' -filter "system.webServer/advancedLogging/server/logDefinitions/logDefinition[@baseFileName='%COMPUTERNAME%-Server']/selectedFields" -name "." -value @{id='VIP_Name';logHeaderName='VIP_Name'}