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
fireburn11Asked:
Who is Participating?
 
KenMcFConnect With a Mentor Commented:
@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
 
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
Evaluating UTMs? Here's what you need to know!

Evaluating a UTM appliance and vendor can prove to be an overwhelming exercise.  How can you make sure that you're getting the security that your organization needs without breaking the bank? Check out our UTM Buyer's Guide for more information on what you should be looking for!

 
fireburn11Author Commented:
i dont think the script is working, there is no variable declared..
0
 
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
All Courses

From novice to tech pro — start learning today.