How do I use variables inside condition statements?

This topic contains 1 reply, has 2 voices, and was last updated by  js 1 week, 4 days ago.

  • Author
  • #100446



    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"}
  • #100449


    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

You must be logged in to reply to this topic.