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

后端 未结 14 913
北恋
北恋 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条回答
  •  Happy的楠姐
    2020-12-25 09:51

    I just started using PowerShell with PowerShell Core 6.0 (beta) and following simply works:

    if ($members.NoteProperty) {
       # NoteProperty exist
    }
    

    or

    if (-not $members.NoteProperty) {
       # NoteProperty does not exist
    }
    

提交回复
热议问题