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,335 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
Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

 
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
 
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

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Powershell 'Like' Command Query 5 32
Powershell  and PSExec = Password failure 5 21
Never expired checked 2 18
Powershell File Sort 8 24
This is a PowerShell web interface I use to manage some task as a network administrator. Clicking an action button on the left frame will display a form in the middle frame to input some data in textboxes, process this data in PowerShell and display…
Create and license users in Office 365 in bulk based on a CSV file. A step-by-step guide with PowerShell script examples.
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…
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…

805 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