How do I use variables inside condition statements?

Hello,

I have object and I want to use property of that object inside condition statement. How do I do that. Example is below. Object is called Diff and I want to use “PropertyName” property as a search condition in “Where” clause for second statement. How do I do that? In this specific case it’s groups but needs to be dynamic.

[DBG]: PS C:\gd\Documents\Projects\WHSSF> $diff | fl * -force


PropertyName : groups
RefValue     : ADSyncAdmins
DiffValue    : {ADSyncOperators, ADSyncAdmins}

[DBG]: PS C:\gd\Documents\Projects\WHSSF> $users | where {$_.groups -eq "ADSyncAdmins"}

Like this?

PS /Users/js> $prop = 'name'                                                          
PS /Users/js> get-process | where {$_.$prop -eq 'trustd'}              

 NPM(K)    PM(M)      WS(M)     CPU(s)      Id  SI ProcessName
 ------    -----      -----     ------      --  -- -----------
      0     0.00      14.67     560.57    5995   1 trustd