激活IIS站点日志记录字段[PowerShell] [英] Activate IIS site logging field [PowerShell]

查看:62
本文介绍了激活IIS站点日志记录字段[PowerShell]的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有一种方法(最好通过PowerShell)激活IIS中特定网站上的日志记录字段?

Is there a way to activate logging fields on a specific website in IIS, preferably through PowerShell?

我想激活客户端IP地址"日志记录字段,而无需将RDP发送到计算机并手动进行设置.

I want to activate the 'Client IP Address' logging field without needing to RDP to the machine and setting it manually.

我正在运行带有IIS 8.5的Windows Server 2012

I am running Windows Server 2012 with IIS 8.5

推荐答案

经过更多搜索后,我在以下位置找到了自己的解决方案的基准:通过PowerShell设置IIS日志字段

After a bit more searching, I found a baseline for my own solution at: Set IIS Log Fields via PowerShell

Activate-LoggingField函数将网站名称和日志记录字段名称作为参数

The Activate-LoggingField function takes in a website name and logging field name as parameters

它通过Get- WebConfigurationProperty cmdlet并检查是否存在提供的日志记录字段.如果不存在,它将尝试通过 Set-WebConfigurationProperty cmdlet

It gets the supplied website's active logging fields via the Get-WebConfigurationProperty cmdlet and checks if the supplied logging field is present. If it is not present, it will attempt to add it via the Set-WebConfigurationProperty cmdlet

Import-Module Webadministration

Function Activate-LoggingField
{
    param([Parameter(Mandatory=$true)][string]$websiteName,
          [Parameter(Mandatory=$true)][string]$loggingField)

    $loggingFilter = "/system.applicationHost/sites/site[@name=`"$websiteName`"]/LogFile"
    $currentLoggingFields = Get-WebConfigurationProperty -Filter $loggingFilter -Name LogExtFileFlags
    if ($currentLoggingFields -notmatch $loggingField)
    {
        $newLoggingFields = "$currentLoggingFields,$loggingField"
        Set-WebConfigurationProperty -Filter $loggingFilter -Name LogExtFileFlags -Value $newLoggingFields
    }
}

Activate-LoggingField -websiteName "MySite" -loggingField "ClientIP"

这篇关于激活IIS站点日志记录字段[PowerShell]的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆