Share via

Get-ADUser Syntax problems...

TheLionFox 96 Reputation points
2021-02-09T06:49:42.143+00:00

Hey,

can someone tell me how i can manage to get this line of code working ?
Problem is that $x is not seen/accepted as variable....

$usn = (Get-ADUser -Filter {EmailAddress -eq "$x"} -Properties * -SearchBase "dc=xyz" -Server xyz.i:123 | Select *).SamAccountName

the position of $x must be a variable, but somehow it's not reading it as a variable and i got no output...

Windows for business | Windows Server | User experience | PowerShell
0 comments No comments

Answer accepted by question author

TheLionFox 96 Reputation points
2021-02-09T07:47:58.49+00:00

After Scraping the Internet for a day i found a solution that works..

$usn = (Get-ADUser -Filter "EmailAddress -eq '$x'" -Properties * -SearchBase "dc=xyz" -Server xyz.i:123 | Select *).SamAccountName

thanks anyway :)

Best regards,

TheLionFox

Was this answer helpful?

0 comments No comments

1 additional answer

Sort by: Most helpful
  1. Anonymous
    2021-02-09T07:24:09.317+00:00

    Hi,

    If curly braces are used to enclose the filter, the variable should not be quoted

    $usn = (Get-ADUser -Filter {EmailAddress -eq $x} -Properties * -SearchBase "dc=xyz" -Server xyz.i:123 | Select *).SamAccountName  
    

    Best Regards,
    Ian Xue

    ============================================

    If the Answer is helpful, please click "Accept Answer" and upvote it.
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    Was this answer helpful?


Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.