使用Powershell命令在IIS高级日志记录的日志定义中启用日志记录字段

时间:2020-04-08 13:33:59

标签: powershell iis advanced-custom-fields iis-advanced-logging

我正在寻找一个Powershell脚本来启用IIS高级日志记录中的一个日志记录定义中的字段。

请参见以下屏幕截图。

Enable Fields in log definition of IIS advanced logging

我尝试了以下命令。

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

我收到以下错误

Set-WebConfigurationProperty:意外的令牌输入: get-config(“ MACHINE / WEBROOT / APPHOST”)/ system.webServer / advancedLogging / Server / log 定义/ [@ baseFileName ='%COMPUTERNAME%-Server'] /字段位置: 93长度:1片段:[在D:\ AdvanceLogging.ps1:10 char:1 + Set-WebConfigurationProperty -Filter“ system.webServer / advancedLoggin ... + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~ + CategoryInfo:未指定:(:) [Set-WebConfigurationProperty],参数tException + FullyQualifiedErrorId:System.ArgumentException,Microsoft.IIs.PowerShell.Provide
r.SetConfigurationPropertyCommand

我不知道上面的命令是否正确,有人可以帮忙吗?

1 个答案:

答案 0 :(得分:1)

如果要在服务器节点中添加该过滤器,请尝试此操作。

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'}

如果要在网站级别设置过滤器,请使用此命令。

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'}