locked
ps script to get AD attribute by email RRS feed

  • Question

  • Hello!

    I need some advice. I user this PS line

    Get-ADUser -Filter "EmailAddress -eq 'x.y@xy.com'" -Properties extensionAttribute4

    I would like to make a tool to be able to copy only the email address and it gives back the attribute. I just don know where to start.

    • Moved by Bill_Stewart Wednesday, January 2, 2019 3:21 PM This is not "scripts on demand"
    Thursday, November 1, 2018 11:14 AM

All replies

  • I'm not sure I understand what you are trying to achieve but maybe something like this:

    $User = Get-ADUser -Filter "emailaddress 'user@domain.local'" -Properties extensiomAttribute4

    $User.extensionAttribute4

    Thursday, November 1, 2018 11:21 AM
  • With the mentioned ps line I get the extensionAttribute4 value already.

    I would like to make something in ISE which asks only for email address, and gives the attribute.

    So I could simply copy the address from an email, paste to command prompt, hit enter and get the needed parameter. Sorry if I wasnt explained clearly.


    • Edited by sefhans Thursday, November 1, 2018 11:54 AM
    Thursday, November 1, 2018 11:53 AM
  • Dai forgot the -eq operator in the filter. If you want to pass the email address to the script, or prompt for the email, I would suggest code similar to:

    If ($Args.Count -eq 1) {$Email = $Args[0]}
    Else {$Email = Read-Host "Enter the email address of the user"}
    $User = (Get-ADUser -Filter {EmailAddress -eq $Email} -Properties extensionAttribute4
    $User.extensionAttribute4

    Edit: Help for the Read-Host cmdlet:

    https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.utility/read-host?view=powershell-6

    $Args is an automatic variable:

    https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_automatic_variables?view=powershell-6


    Richard Mueller - MVP Enterprise Mobility (Identity and Access)


    Thursday, November 1, 2018 11:57 AM