I have a complex script that evaluates “attributes” from a web service.
I build a list of all attributes and information about them in a list called $global:attributes and determine if they are single/multivalue value and are references.
Below is a snippet:
#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
Now the following commands return “true” right?
(($global:attributes | where { $_.AttributeName -eq "Applications" }).IsReference -eq $true)
(($global:attributes | where { $_.AttributeName -eq "Applications" }).IsMultiValued -eq $true)
So why does the given function below doesn’t evaluate as expected? Is it because I am invoking the where clause in a nested if statement?
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"
}
}
}
This command
doTest -key "Applications" returns
Applications is of type Reference
Applications is single value
Should be multivalued, right?
You have a typo in your code above… “IsMulitValued” instead of “IsMultiValued”. When I changed that and ran it locally it produced your expected output.