none
To Get-ADUser or not to GetADUser that is the question RRS feed

  • Question

  • I've been researching this for a month now and have read everything about variables in powershell and get-adobject I could get my greedy little hands on. I still don't get it.

    I tried to get an email address from AD, but I couldn't get the command to return the email address into a variable. It looks like the get-aduser command is not able to find the user because the $owners has the name stored as "John Smith." Can you please help me understand how to search AD for a user by a string containing first name space last name when everything in AD is stored last name comma first name so I can get this thing finished? Am I approaching this wrong? Would it be easier to convert "John Smith" to an email address using John.Smith at whatever? I've already tested everything else and verified that it's working. This is the only piece of a much larger script that is holding me up and worse making me feel like an idiot.

    $EmailAddress = Get-ADUser $owner -properties email -server ads.domain.local | select-object email

    I get this error :

    Get-ADUser : Error parsing query: 'Bill Jilesen' Error Message: 'syntax error' at position: '6'.
    At line:1 char:1
    + Get-ADUser -filter $owner -searchbase "dc=delaval,dc=local" -credential delaval\ ...
    + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
        + CategoryInfo          : ParserError: (:) [Get-ADUser], ADFilterParsingException
        + FullyQualifiedErrorId : Error parsing query: 'Bill Jilesen' Error Message: 'syntax error' at position: '6'.,Microsoft.ActiveDirectory.Management
       .Commands.GetADUser

    Tuesday, June 17, 2014 6:16 PM

Answers

All replies