• Status: Solved
  • Priority: Low
  • Security: Public
  • Views: 59
  • Last Modified:

export list from exchange for email id and phone numbers

I need to get my AD user's primary email id and phone numbers, the issue i am facing here is that i dont have the display name i just have their first and last name, so when i run ps script with the first and last name in exchange powershell it thorws an error that the object cannot be found and it works when i give their display name.

Any idea how can i find their email id and phone numbers just with their first and last name
i have a list for 1000 users
0
abdull sheriff
Asked:
abdull sheriff
2 Solutions
 
Alex Green3rd Line Server SupportCommented:
Consolidate their first and last name into a single text file.

$Users =  import-content "c:\temp\users.txt
Foreach ($user in $Users) {Get-ADUser -Filter { displayName -like "*$User*" } | Select-object Samaccountname, email, telephoneNumber| Expoprt-csv C:\temp\results.csv}
1
 
abdull sheriffSystems EngineerAuthor Commented:
[PS] C:\Windows\system32>$Users =  import-content "c:\user1.txt" Foreach ($user in $Users) {Get-ADUser -Filter { display
Name -like "*$User*" } | Select-object Samaccountname, email, telephoneNumber| Expoprt-csv C:\results.csv}
Unexpected token 'in' in expression or statement.
At line:1 char:58
+ $Users =  import-content "c:\user1.txt" Foreach ($user in <<<<  $Users) {Get-ADUser -Filter { displayName -like "*$Us
er*" } | Select-object Samaccountname, email, telephoneNumber| Expoprt-csv C:\results.csv}
    + CategoryInfo          : ParserError: (in:String) [], ParentContainsErrorRecordException
    + FullyQualifiedErrorId : UnexpectedToken

when i run i get this error and i am running this in exchange powershell and i have my user list txt file under c
0
 
Alex Green3rd Line Server SupportCommented:
$Users = import-content "c:\temp\users.txt"
Foreach ($user in $Users) {Get-ADUser -Filter { displayName -like "*$User*" } | Select-object Samaccountname, email, telephoneNumber| Expoprt-csv C:\temp\results.csv}


Missing closing "
0
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

 
abdull sheriffSystems EngineerAuthor Commented:
i included the " when i run the command , you can see it in my output
0
 
Alex Green3rd Line Server SupportCommented:
$Users = get-content "c:\temp\users.txt"
Foreach ($user in $Users) {Get-ADUser -Filter { displayName -like "*$User*" } -properties * | Select-object Samaccountname, email, telephoneNumber| Export-csv C:\temp\results.csv}
0
 
abdull sheriffSystems EngineerAuthor Commented:
it ran this time but the file is with 0kb, its blank
0
 
Alex Green3rd Line Server SupportCommented:
$Users = get-content "c:\temp\users.txt"
Foreach ($user in $Users) {Get-ADUser -LDAPFilter "(Displayname=$User)" -properties * | Get-ADUser -Properties * | Select-Object Name, Samaccountname, mail, OfficePhone | export-csv C:\temp\results.csv -append}


Apparenlty it doesn't like searching on a displayname. This does 100 work
0
 
abdull sheriffSystems EngineerAuthor Commented:
ok this works when the txt file have users with display name in it

thanks for helping me out here , let me rephrase my issue again

for instance :
the script works when the txt file have a user like Abdull Sheriff Accounts Manager
the script does not works when the txt file have a user like Abdull Sheriff

My problem here i have a list of users with their first and last name only and i dont have their display name

First Name: Abdull
Last Name: Sheriff
Display Name : Abdull Sheriff Accounts Manager
0
 
abdull sheriffSystems EngineerAuthor Commented:
i am okay to have a script where i can first get their the display name with first or last name and then run the script with the display name in the txt file
0
 
Alex Green3rd Line Server SupportCommented:
Urgh, this is a shocking way to set up AD...

Fine,

$names = Import-CSV .\users.csv -Header Givenname,Surname -Delimiter ";"
ForEach ($Name in $Names)
{
    $FirstFilter = $Name.Givenname
    $SecondFilter = $Name.Surname
    Get-ADUser -Filter { GivenName -like $FirstFilter -and Surname -like $SecondFilter} |select enabled,samaccountname,@{n="ou";e={($_.distinguishedname -split ",*..=")[2]}}
}

That'll give you the samaccounnnames

Then do

$Users = get-content "c:\temp\users.txt"
Foreach ($user in $Users) {Get-ADUser -identity $user -properties * | Select-object Samaccountname, email, telephoneNumber| Export-csv C:\temp\results.csv}
0
 
Aaron GuilmetteTechnology Solutions ProfessionalCommented:
Why not just get *everyone's* data and then sort through it with Excel or use further PowerShell to limit it?

Get-Aduser -Filter * | ? { $_.DisplayName -ne $null } | Select DisplayName,givenName,sn,telephoneNumber

or something similar?
1
 
Mohammad Ishtyaq KhatriCommented:
As mentioned by @Aaron Guilmette do a All users and then do a Vlookup in Excel to match the first name last name from the list you have.

You should get what you need ;)
0
 
abdull sheriffSystems EngineerAuthor Commented:
When running the below i get all the information except for mobile,

Import-Module activedirectory
$path = "c:\ADUsers123.csv"
Get-ADUser -Filter * |
Select-Object name, enabled, Mobile, userprincipalname, Samaccountname, email, telephoneNumber | Export-Csv -Path $path -NoTypeInformation

i tried mobile, telephoneNumber still the same, any wrong in the script???
0
 
abdull sheriffSystems EngineerAuthor Commented:
thanks all
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Protect Your Employees from Wi-Fi Threats

As Wi-Fi growth and popularity continues to climb, not everyone understands the risks that come with connecting to public Wi-Fi or even offering Wi-Fi to employees, visitors and guests. Download the resource kit to make sure your safe wherever business takes you!

Tackle projects and never again get stuck behind a technical roadblock.
Join Now