where -in wildcards

Welcome Forums General PowerShell Q&A where -in wildcards

Viewing 4 reply threads
  • Author
    Posts
    • #43754
      Participant
      Topics: 29
      Replies: 59
      Points: 165
      Rank: Participant

      what’s a better way to say

      | where {$_.property -like “*this*” -or $_.property -like “*that*” -or $_.property -like “*theOther*}

      is “where property -in (….)” supposed to work with wildcards?

    • #43768
      Keymaster
      Topics: 18
      Replies: 4872
      Points: 1,903
      Helping HandTeam Member
      Rank: Community Hero

      -in does not work with wildcards, no, nor does it do what I think you’re thinking. -in is a logical opposite of -contains, and it checks for an object’s membership in a collection. It isn’t like the T-SQL “IN” clause. There is no syntax for “-in (…)” in PowerShell.

      You could do this:

      $possibles = @('this','that','theOther')
      where {$_.property -in $possibles}
      
    • #43770
      Participant
      Topics: 29
      Replies: 59
      Points: 165
      Rank: Participant

      I think I need the wildcards. The value of property is going to be “something this etc” or “something that etc”

    • #43774
      Member
      Topics: 9
      Replies: 2322
      Points: 0
      Rank: Member

      Personally, I’d use the -match operator here, since regex has an “or” operator built-in:

      $something | Where { $_.property -match 'this|that|theother' }
      
    • #43776
      Participant
      Topics: 29
      Replies: 59
      Points: 165
      Rank: Participant

      thanks Dave, match seems to be working.

      my script is looking for expiring certificates from the Local Machine’s Personal store, Trusted Root CA store, and Intermediate CA store, but I really only care about certificates that were issued by certain (internal) entities– mainly because there are some really old, expired trusted root certificates that I think maybe the OS depends on, so I don’t want to delete them. but the format of the certificate “subject” (aka the ‘property’ in my original question) is not consistent. most of the time it’s “CN=Some CA,OU=Some Department,O=That Company”, etc., but occasionally it’s an email address someguy@theother.com.

Viewing 4 reply threads
  • The topic ‘where -in wildcards’ is closed to new replies.