PowerShell Script

I'm running a script in PowerShell that list all the users first name, last name and e-mail address than exports them to a csv file. I get the columns for first and last name but a blank column in e-mail address, can somebody help? I will really appreciate it. Here's the script:

Import-Module ActiveDirectory
Get-ADUser -SearchBase “OU=people,dc=sanjosefoothillfamilycomm,dc=local” -Filter *  |
 Select givenname, surname, emailaddress |
 Export-Csv "C:\Users\narce\Desktop\script1.csv"
FCHCAdminAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

oBdACommented:
Because the attribute is named just "mail"
Import-Module ActiveDirectory
 Get-ADUser -SearchBase "OU=people,dc=sanjosefoothillfamilycomm,dc=local" -Filter *  |
  Select givenname, surname, mail |
  Export-Csv "C:\Users\narce\Desktop\script1.csv"

Open in new window

0
FCHCAdminAuthor Commented:
I ran the script with only "mail" but get the same result. I'm testing the script so I only created an e-mail address for the first user in the list " "nkozuma" but is not showing in the mail column. Also if I go to AD users and computers under nkozuma in the general tab I can see the e-mail address, attached is the csv file,  any ideas?
script1.csv
0
oBdACommented:
Sorry, forgot the property; mail is no part of the default set:
Import-Module ActiveDirectory
 Get-ADUser -SearchBase “OU=people,dc=sanjosefoothillfamilycomm,dc=local” -Filter * -Property mail |
  Select givenname, surname, emailaddress |
  Export-Csv "C:\Users\narce\Desktop\script1.csv"

Open in new window

0
Creating Active Directory Users from a Text File

If your organization has a need to mass-create AD user accounts, watch this video to see how its done without the need for scripting or other unnecessary complexities.

FCHCAdminAuthor Commented:
That was my original script (in the problem description) and is not working. That's the problem
0
oBdACommented:
Sorry again, wrong clipboard; but it's not quite the same, check the arguments for Get-ADUser.
Import-Module ActiveDirectory
 Get-ADUser -SearchBase "OU=people,dc=sanjosefoothillfamilycomm,dc=local" -Filter *  -Property mail |
  Select givenname, surname, mail |
  Export-Csv "C:\Users\narce\Desktop\script1.csv" 

Open in new window

1

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
footechCommented:
BTW, even though the ldapDisplayName of the attribute is "mail", specifying "EmailAddress" to the -Properties parameter will also work.  This is just an example of the Get-ADUser cmdlet doing some magic behind the scenes (basically providing some aliases for certain properties).  So the following will also work.
Import-Module ActiveDirectory
Get-ADUser -SearchBase "OU=people,dc=sanjosefoothillfamilycomm,dc=local" -Filter *  -Properties emailaddress |
  Select givenname, surname, emailaddress |
  Export-Csv "C:\Users\narce\Desktop\script1.csv" -notype

Open in new window

1
FCHCAdminAuthor Commented:
Both ObDa and footech worked, thank you.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Powershell

From novice to tech pro — start learning today.