Solved

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

Posted on 2012-03-27
9
3,214 Views
Last Modified: 2012-04-24
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
Comment
Question by:fireburn11
  • 4
  • 3
  • 2
9 Comments
 
LVL 14

Expert Comment

by:athomsfere
ID: 37771695
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
 

Author Comment

by:fireburn11
ID: 37771724
Hi Ahomsfere,

Is there a get-qaduser missing in there?
0
 

Author Comment

by:fireburn11
ID: 37771737
i dont think the script is working, there is no variable declared..
0
 
LVL 27

Expert Comment

by:KenMcF
ID: 37772139
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
Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

 
LVL 27

Expert Comment

by:KenMcF
ID: 37772145
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
 
LVL 14

Expert Comment

by:athomsfere
ID: 37772244
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
 
LVL 27

Expert Comment

by:KenMcF
ID: 37772274
@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
 

Author Comment

by:fireburn11
ID: 37774389
well, actually, that is what i try to avoid, I need the csv file to include all user's selected attributes.

Thanks
0
 
LVL 27

Accepted Solution

by:
KenMcF earned 500 total points
ID: 37774414
@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

Featured Post

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Citrix XenApp, Internet Explorer 11 set to Enterprise Mode and using central hosted sites.xml file.
"Migrate" an SMTP relay receive connector to a new server using info from an old server.
This video Micro Tutorial explains how to clone a hard drive using a commercial software product for Windows systems called Casper from Future Systems Solutions (FSS). Cloning makes an exact, complete copy of one hard disk drive (HDD) onto another d…
With the advent of Windows 10, Microsoft is pushing a Get Windows 10 icon into the notification area (system tray) of qualifying computers. There are many reasons for wanting to remove this icon. This two-part Experts Exchange video Micro Tutorial s…

758 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now