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

后端 未结 14 897
北恋
北恋 2020-12-25 09:01

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

Appreciate I can do ...

$members = Get-Member -InputObject $myobject 

and th

14条回答
  •  失恋的感觉
    2020-12-25 09:52

    Just to clarify given the following object

    $Object
    

    With the following properties

    type        : message
    user        : john.doe@company.com
    text        : 
    ts          : 11/21/2016 8:59:30 PM
    

    The following are true

    $Object.text -eq $NULL
    $Object.NotPresent -eq $NULL
    
    -not $Object.text
    -not $Object.NotPresent
    

    So the earlier answers that explicitly check for the property by name is the most correct way to verify that that property is not present.

提交回复
热议问题