• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 3766
  • Last Modified:

powershell script to read in user's email address then generate a csv file with samaccount, and other attributes

Hi Guys,

I need  a PS to read in a text file that contains bunch user's email address then out put name, samaccountname, and extensionattribute9 to a csv file.

Please help!

Thanks
0
fireburn11
Asked:
fireburn11
  • 4
  • 3
  • 2
1 Solution
 
athomsfereCommented:
I personally like Quests Active Directory tools

Here is a script using QAD

Get-Content 'ImportPath' | ForEach-Object
	{
	Select-Object Name, SamAccountName, ExtensionAttribute9 | Export-Csv 'ExportPath'
	}

Open in new window

0
 
fireburn11Author Commented:
Hi Ahomsfere,

Is there a get-qaduser missing in there?
0
 
fireburn11Author Commented:
i dont think the script is working, there is no variable declared..
0
Making Bulk Changes to Active Directory

Watch this video to see how easy it is to make mass changes to Active Directory from an external text file without using complicated scripts.

 
KenMcFCommented:
Try this

$Users = get-content c:\temp\emailaddresses.txt
$Users | foreach {
    Get-QADUser -Email $Mail
} | Select samaccountname, mail | Export-Csv c:\temp\mailtest.csv -NoTypeInformation
0
 
KenMcFCommented:
had a typo


$Users = get-content c:\temp\emailaddresses.txt
$Users | foreach {
    Get-QADUser -Email $_
} | Select samaccountname, mail | Export-Csv c:\temp\mailtest.csv -NoTypeInformation
0
 
athomsfereCommented:
Sorry, yes I forgot to include the variable / user:

Get-Content 'ImportPath' | ForEach-Object
	{
         Get-QADUser -Email $_ | `
	Select-Object Name, SamAccountName, ExtensionAttribute9 | Export-Csv 'ExportPath'
	}

Open in new window

0
 
KenMcFCommented:
@athomsfere

your CSV file will be overwritten with every user, so you will only get the results for the last user in the CSV file.
0
 
fireburn11Author Commented:
well, actually, that is what i try to avoid, I need the csv file to include all user's selected attributes.

Thanks
0
 
KenMcFCommented:
@fireburn11

Look at what I had posted before, I think this will get you what you want. Just change the input file and export file location



$Users = get-content c:\temp\emailaddresses.txt
$Users | foreach {
    Get-QADUser -Email $_
} | Select samaccountname, mail | Export-Csv c:\temp\mailtest.csv -NoTypeInformation
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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 4
  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now