ObjSearcher using -like on a variable

This topic contains 2 replies, has 2 voices, and was last updated by Profile photo of David Schmidtberger David Schmidtberger 10 months, 1 week ago.

  • Author
  • #33054
    Profile photo of David Schmidtberger
    David Schmidtberger

    I have some working code that looks like this:
    $strFilter = "(&(objectCategory=User)("+$SCriteria+"="+$SValue+"))"
    $objSearcher.Filter = $strFilter

    using this in some ad searching functionality, what I'm trying to do is on the second = in strfilter IE the criteria matching supplied value, to change to -like
    most common use on this piece is searching ad accounts for an employee id field, where users can have multiple accounts, the primary having a letter preceeding a string of digits, and the secondary account only has the digits.
    right now I can only search on specific values, I need to be able to do a -like $SValue

    I know this is a bit rambling but any assistance would be appreciated

  • #33055
    Profile photo of Don Jones
    Don Jones

    That filter is processed by AD, not PowerShell, and so -like (or any other shell operator) isn't valid. But * is a valid wildcard; see if http://stackoverflow.com/questions/9564120/using-wildcards-in-ldap-search-filters-queries doesn't help.

  • #33056
    Profile photo of David Schmidtberger
    David Schmidtberger

    thanks Don, was trying to edit someone else's code, not really sure why he had the + preceeding and trailing the values...

    but managed to have this work:
    $strFilter = "(&(objectCategory=User)($SCriteria=*$SValue))"


You must be logged in to reply to this topic.