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

后端 未结 14 829
北恋
北恋 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 10:03

    If you are using StrictMode and the psobject might be empty, it will give you an error.

    For all purposes this will do:

        if (($json.PSobject.Properties | Foreach {$_.Name}) -contains $variable)
    
    0 讨论(0)
  • 2020-12-25 10:05

    For identifying which of the objects in an array have a property

    $HasProperty = $ArrayOfObjects | Where-Object {$_.MyProperty}
    
    0 讨论(0)
提交回复
热议问题