ObjSearcher using -like on a variable

This topic contains 2 replies, has 2 voices, and was last updated by  David Schmidtberger 1 year, 8 months ago.

  • Author
    Posts
  • #33054

    David Schmidtberger
    Participant

    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

    Don Jones
    Keymaster

    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

    David Schmidtberger
    Participant

    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))"

    thanks

You must be logged in to reply to this topic.