简体   繁体   中英

Remove IIS custom log field with PowerShell

I'm trying to delete a custom log field on IIS using PowerShell. 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:

$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  -pspath 'MACHINE/WEBROOT/APPHOST'  -filter "system.applicationHost/sites/siteDefaults/logFile/customFields" -name "." -AtElement @{logFieldName='TE'};

Just tested and it works

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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