简体   繁体   English

使用 PowerShell 删除 IIS 自定义日志字段

[英]Remove IIS custom log field with PowerShell

I'm trying to delete a custom log field on IIS using PowerShell.我正在尝试使用 PowerShell 删除 IIS 上的自定义日志字段。 I'm using我正在使用

Remove-WebConfigurationProperty -PSPath "MACHINE/WEBROOT/APPHOST" -Filter "system.applicationHost/sites/siteDefaults/logFile/customFields/add[logFieldName='TE']" -Name "." -AtIndex 0 

But I get the following message:但我收到以下消息:

WARNING: Target configuration object 'system.applicationHost/sites/siteDefaults/logFile/customFields/add[logFieldName=TE] is not found at path 'MACHINE/WEBROOT/APPHOST'.

How can I delete the custom field?如何删除自定义字段?

I'm not sure if your approach will work or not, however you can easily remove custom log fields by:我不确定您的方法是否有效,但是您可以通过以下方式轻松删除自定义日志字段:

  • Getting the current value (a string containing a comma separated list of field names)获取当前值(包含以逗号分隔的字段名称列表的字符串)
  • Use Replace to remove the desired field-name and spare comma from the string使用替换从字符串中删除所需的字段名称和备用逗号
  • Set the custom log field property to your updated field list.将自定义日志字段属性设置为更新的字段列表。

In POSH:在 POSH 中:

$currentFields = Get-WebConfigurationProperty -Filter System.Applicationhost/Sites/SiteDefaults/logfile -Name LogExtFileFlags

$currentFields = $currentFields.Replace(",TE", "");

Set-WebConfigurationProperty -Filter System.Applicationhost/Sites/SiteDefaults/logfile -Name LogExtFileFlags -Value $currentFields

For future refences: The correct Remove-WebConfigurationProperty cmdlet to run is:供将来参考:要运行的正确Remove-WebConfigurationProperty cmdlet 是:

Remove-WebConfigurationProperty  -pspath 'MACHINE/WEBROOT/APPHOST'  -filter "system.applicationHost/sites/siteDefaults/logFile/customFields" -name "." -AtElement @{logFieldName='TE'};

Just tested and it works刚刚测试,它的工作原理

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM