[powershell] How can you test if an object has a specific property?

How can you test if an object has a specific property?

Appreciate I can do ...

$members = Get-Member -InputObject $myobject 

and then foreach through the $members, but is there a function to test if the object has a specific property?

Additional Info: The issue is I'm importing two different sorts of CSV file, one with two columns, the other with three. I couldn't get the check to work with "Property", only with "NoteProperty" ... whatever the difference is

if ( ($member.MemberType -eq "NoteProperty" ) -and ($member.Name -eq $propertyName) ) 

This question is related to powershell powershell-3.0

The answer is


Like this?

 [bool]($myObject.PSobject.Properties.name -match "myPropertyNameToTest")

Similar questions with powershell tag:

Similar questions with powershell-3.0 tag: