Windows Vista Forums
Vista Forums Home Join Vista Forums Donate Vista Tutorials Tags

Welcome to Vista Forums we are your forum to discuss Windows Vista x64 and x86 systems. Whether you need help or just want to post an idea you have on Vista, this is the forum for you.
Register at Vista forums...the world biggest Windows Vista resource Join Vista Forums Now

Go Back   Vista Forums > Microsoft Technical Newsgroups > PowerShell

How to use a variable as Ldapfilter

Update your Vista Drivers Update Your Drivers Now!!
Closed Thread
 
Thread Tools Display Modes
Old 05-13-2008   #1 (permalink)
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
Old 05-13-2008   #2 (permalink)
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:
Quote:

> 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
Old 05-13-2008   #3 (permalink)
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:
Quote:

> 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:
>
Quote:

> > 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
Closed Thread

Thread Tools
Display Modes



Similar Threads
Thread Thread Starter Forum Replies Last Post
RE: variable identification Rob Campbell PowerShell 1 03-28-2007 04:02 AM
complex variable bdsherman@gmail.com PowerShell 6 02-22-2007 11:01 AM
Set-Variable Fred J. PowerShell 3 10-25-2006 12:39 PM
tab and variable hn PowerShell 8 10-20-2006 06:40 AM
How can I ensure that a variable is a built-in powershell variable? Sung M Kim PowerShell 7 09-22-2006 06:28 PM


Update your Vista Drivers Update Your Vista Drivers Now!!

Vistax64.com is an independent web site and has not been authorized,
sponsored, or otherwise approved by Microsoft Corporation.
"Windows Vista", the Start Orb, and related materials are trademarks of Microsoft Corp.
© Designer Media 2005-2008
Page generated in 0.26627 seconds with 10 queries