Powershell 如何从高级属性获取LogEventOn值?

Powershell 如何从高级属性获取LogEventOn值?,powershell,iis,Powershell,Iis,我想从IIS应用程序池中每个条目的所有属性生成一个报告 我无法从红色标记的属性中获取值 读取所有其他值都不是问题。。仅使用logEventOn值。我先给你看我的代码: $ConfigSection = Get-IISConfigSection -SectionPath "system.applicationHost/applicationPools" $SitesCollection = Get-IISConfigCollection -ConfigElement $ConfigSection

我想从IIS应用程序池中每个条目的所有属性生成一个报告

我无法从红色标记的属性中获取值

读取所有其他值都不是问题。。仅使用logEventOn值。我先给你看我的代码:

$ConfigSection = Get-IISConfigSection -SectionPath "system.applicationHost/applicationPools"

$SitesCollection = Get-IISConfigCollection -ConfigElement $ConfigSection

$Site = Get-IISConfigCollectionElement -ConfigCollection $SitesCollection -ConfigAttribute @{"name" = "DefaultAppPool"}

$Elem = Get-IISConfigElement -ConfigElement $Site -ChildElementName "recycling"

Get-IISConfigAttributeValue -ConfigElement $Elem -AttributeName "logEventOnRecycle"
这将提供以下输出,这些是logEventOn的属性:

时间、请求、计划、内存、ISAPI、OnDemand、配置更改、私有内存

现在我尝试编辑Get-IISConfigAttributeValue命令。我尝试了不同的选择,如:

Get-IISConfigAttributeValue -ConfigElement $Elem -AttributeName "logEventOnRecycle/@Time"
Get-IISConfigAttributeValue -ConfigElement $Elem -AttributeName "logEventOnRecycle/Time"
Get-IISConfigAttributeValue -ConfigElement $Elem -AttributeName "logEventOnRecycle.Time"
但我总是收到错误消息,该值不存在


如何塑造命令以获得这些值?

多亏Lex Li找到了此模式定义,您可以像下面这样读取标志值并将其转换为布尔真/假值

# get the Idle Timeout value
$ProcessModel = Get-IISConfigElement -ConfigElement $Site -ChildElementName "processModel"
$flags = $ProcessModel.Attributes["logEventOnProcessModel"].Value
$idleTimeout = [bool]($flags -band 1)             # Idle Time-out Reached

# get the values recorded under Recycle
$Elem = Get-IISConfigElement -ConfigElement $Site -ChildElementName "recycling"
$flags = $Elem.Attributes["logEventOnRecycle"].Value
$onRecycle = @{
    'Time'           = [bool]($flags -band 1)     # Specific Time
    'Requests'       = [bool]($flags -band 2)     # Request Limit Exceeded
    'Schedule'       = [bool]($flags -band 4)     # Regular Time Interval
    'Memory'         = [bool]($flags -band 8)     # Virtual Memory Limit Exceeded
    'IsapiUnhealthy' = [bool]($flags -band 16)    # Isapi Reported Unhealthy
    'OnDemand'       = [bool]($flags -band 32)    # Manual Recycle
    'ConfigChange'   = [bool]($flags -band 64)    # Application Pool Configuration Changed
    'PrivateMemory'  = [bool]($flags -band 128)   # Private Memory Limit Exceeded
}
# use these values like '$onRecycle.ConfigChange' etc.

我认为最好为“OnRecycle”值创建一个哈希表,以将它们放在一起,但如果这是您想要的,您当然可以将它们全部放在单独的变量中。

只是一个暗中操作,但会得到IISConfigAttributeValue-ConfigElement$Elem-AttributeName logEventOnRecycle。时间到了吗?遗憾的是,时间到了。。我真的陷入了这个问题,搜索了一段时间的解决方案:基于模式,它是一个标志字段,所以你需要做一些数学来计算值。我不知道如何开始这个,但我要用谷歌搜索一下,也许我会找到它。@LucaS我想我明白为什么了。IdleTimout位于不同的子元素下。Try$ProcessModel=Get iisconfig-ConfigElement$Site-ChildElementName-ProcessModel$flags=Get-IISConfigAttributeValue-ConfigElement$ProcessModel-AttributeName logEventOnProcessModel$idleTimeout=[bool]$flags-已达到频带1空闲超时。因为这里的评论不接受换行符,所以我更新了我的答案。我自己无法检查,所以请告诉我?不,这不仅是$ProcessModel的行,而且下面的行也发生了更改。IdleTimeout位于模式中名为processModel的元素内。回收属性位于另一个名为recycling的元素中。您已经有了这行代码,并在名为$Elem的变量中捕获了元素。对于IdleTimeout,我们需要使用$ProcessModel变量。@LucaS奇怪。。那么什么是Get IISCOnfiggatTributeValue-ConfigElement$ProcessModel-AttributeName logEventOnProcessModel准确返回的?如果它返回的是字符串而不是整型标志值,那么您的iis_schema.xml与我看到的不同。检查%SystemRoot%\System32\Inetsrv\Config\Schema@LucaS我花了相当长的时间来处理这个问题,最后终于得到了一个数值。。似乎$flags=$ProcessModel.Attributes[logEventOnProcessModel].值是我唯一的工作方式。我已经更改了答案中的密码。如果有更好的方法,我很想听听,但我在任何地方都找不到任何例子,所以。。