0
我有一个复杂的脚本来评估Web服务的“属性”。 我在名为$ global:attributes的列表中构建了所有属性及其相关信息的列表,并确定它们是单值/多值还是参考。Powershell - Where Clause意外的行为?
下面是一个片段:
#Build the object
$obj = new-object object
$obj | Add-Member -MemberType NoteProperty -Name AttributeName -Value "Applications"
$obj | Add-Member -MemberType NoteProperty -Name IsReference -Value $true
$obj | Add-Member -MemberType NoteProperty -Name IsMultiValued -Value $true
$global:attributes = $obj
现在下面的命令返回 “真” 吗?
(($global:attributes | where { $_.AttributeName -eq "Applications" }).IsReference -eq $true)
(($global:attributes | where { $_.AttributeName -eq "Applications" }).IsMultiValued -eq $true)
那么为什么下面给出的函数没有按预期那样评估呢?是否因为我调用嵌套if语句中的where子句?
Function doTest($key)
{
if (($global:attributes | where { $_.AttributeName -eq $key}).IsReference -eq $true)
{
write-host "$key is of type Reference"
if (($global:attributes | where { $_.AttributeName -eq $key}).IsMulitValued -eq $true)
{
write-host "$key is multivalued"
}
else {
write-host "$key is single value"
}
} else {
if (($global:attributes | where { $_.AttributeName -eq $key}).IsMultiValued -eq $true)
{
write-host "$key is Multivalue other"
} else {
write-host "$key is single value other"
}
}
}
此命令 doTest -key "Applications"
返回
Applications is of type Reference
Applications is single value
应该是多值的,对不对?
我讨厌被阅读障碍:( –