Windows Vista Forums

How to use a variable as Ldapfilter
  1. #1


    Bruno Guest

    How to use a variable as Ldapfilter

    Hi,
    I have a list of email addresses for which i need to find the associated
    samaccountname in AD.
    the email addresses are standard (first.last@xxxxxx)
    Here is the script i use (with Quest extensions)

    $addresses = Get-Content c:\emaillist.txt

    Foreach ($mad in $addresses)
    {
    $lfilter = "'(mail=$mad)'"

    $user = Get-QADUser -LdapFilter $lfilter

    $user
    }

    for user first.last@xxxxxx
    $lfilter would return '(mail=first.last@xxxxxx)'

    When used as a variable, it won't return anything. However if i make a
    manual Get-qaduser -ldapfilter and add the $lfilter content to it, it returns
    the value. Can somebody tell me what i am doing wrong or if there is a better
    solution for this ?
    thanks in advance
    Bruno




      My System SpecsSystem Spec

  2. #2


    Gerd Schneider Guest

    RE: How to use a variable as Ldapfilter

    I'm not using Quest Extensions so I can not test, but just from a formal
    perspective I assume that the extra single quotes in $lfilter are wrong. Try

    $lfilter = "(mail=$mad)"

    --
    Gerd


    "Bruno" wrote:

    > Hi,
    > I have a list of email addresses for which i need to find the associated
    > samaccountname in AD.
    > the email addresses are standard (first.last@xxxxxx)
    > Here is the script i use (with Quest extensions)
    >
    > $addresses = Get-Content c:\emaillist.txt
    >
    > Foreach ($mad in $addresses)
    > {
    > $lfilter = "'(mail=$mad)'"
    >
    > $user = Get-QADUser -LdapFilter $lfilter
    >
    > $user
    > }
    >
    > for user first.last@xxxxxx
    > $lfilter would return '(mail=first.last@xxxxxx)'
    >
    > When used as a variable, it won't return anything. However if i make a
    > manual Get-qaduser -ldapfilter and add the $lfilter content to it, it returns
    > the value. Can somebody tell me what i am doing wrong or if there is a better
    > solution for this ?
    > thanks in advance
    > Bruno
    >

      My System SpecsSystem Spec

  3. #3


    Bruno Guest

    RE: How to use a variable as Ldapfilter

    Hi Gerd, thanks for the prompt answer.

    You were right, it works fine now !

    I thought i had to put both as the ldapfilter requests usually '(xyz)' format.
    I will check that to avoid further mistakes...





    "Gerd Schneider" wrote:

    > I'm not using Quest Extensions so I can not test, but just from a formal
    > perspective I assume that the extra single quotes in $lfilter are wrong. Try
    >
    > $lfilter = "(mail=$mad)"
    >
    > --
    > Gerd
    >
    >
    > "Bruno" wrote:
    >

    > > Hi,
    > > I have a list of email addresses for which i need to find the associated
    > > samaccountname in AD.
    > > the email addresses are standard (first.last@xxxxxx)
    > > Here is the script i use (with Quest extensions)
    > >
    > > $addresses = Get-Content c:\emaillist.txt
    > >
    > > Foreach ($mad in $addresses)
    > > {
    > > $lfilter = "'(mail=$mad)'"
    > >
    > > $user = Get-QADUser -LdapFilter $lfilter
    > >
    > > $user
    > > }
    > >
    > > for user first.last@xxxxxx
    > > $lfilter would return '(mail=first.last@xxxxxx)'
    > >
    > > When used as a variable, it won't return anything. However if i make a
    > > manual Get-qaduser -ldapfilter and add the $lfilter content to it, it returns
    > > the value. Can somebody tell me what i am doing wrong or if there is a better
    > > solution for this ?
    > > thanks in advance
    > > Bruno
    > >

      My System SpecsSystem Spec

How to use a variable as Ldapfilter problems?

Similar Threads
Thread Thread Starter Forum Replies Last Post
$Variable Is In {1,2,3,4} C S S PowerShell 3 23 Oct 2008
Creating A Variable from the Value of Another Luke PowerShell 4 09 Aug 2007
Set-Variable Fred J. PowerShell 3 25 Oct 2006
tab and variable hn PowerShell 8 20 Oct 2006
How can I ensure that a variable is a built-in powershell variable? Sung M Kim PowerShell 7 22 Sep 2006