How can you test if an object has a specific property?
You can use Get-Member
if(Get-Member -inputobject $var -name "Property" -Membertype Properties){
#Property exists
}
Like this?
[bool]($myObject.PSobject.Properties.name -match "myPropertyNameToTest")
This is succinct and readable:
"MyProperty" -in $MyObject.PSobject.Properties.Name
We can put it in a function:
function HasProperty($object, $propertyName)
{
$propertyName -in $object.PSobject.Properties.Name
}