Solved

Need powershell script to get firstname,lastname,emailaddress,displayname of the users

Posted on 2016-10-05
8
74 Views
Last Modified: 2016-11-01
I have a list with bunch of samaccountnames in it. I need a powershell script which can get me firstname,lastname,displayname,emailaddress of the users based on samaccountname file.

Thanks.
0
Comment
Question by:A D
  • 3
  • 2
8 Comments
 
LVL 40

Accepted Solution

by:
Subsun earned 500 total points
Comment Utility
Try..
Import-Module ActiveDirectory
GC C:\input.txt | % {Get-Aduser $_ -Pr * | Select GivenName,Surname,displayname,emailaddress,samaccountname} | Export-csv C:\report.csv -nti

Open in new window

Input file format..
UserA
UserB
UserC

Open in new window

0
 
LVL 32

Expert Comment

by:it_saige
Comment Utility
Perhaps something like:
$users = Get-Content C:\_admin\users.txt
$users | ForEach-Object {
    Get-ADUser $_ -Properties * | Select-Object @{l="First Name";e={$_.GivenName}},@{l="Last Name"
;e={$_.Surname}},@{l="Display Name";e={$_.DisplayName}},@{l="E-mail Address";e={$_.Mail}}
}

Open in new window


-saige-
0
 

Author Comment

by:A D
Comment Utility
Thank you Subsun. It worked perfectly. You're AWESOME!!!
0
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.

 
LVL 40

Expert Comment

by:Subsun
Comment Utility
You are welcome!
0
 

Author Comment

by:A D
Comment Utility
This question can be closed. Thanks
0
 
LVL 40

Expert Comment

by:Subsun
Comment Utility
@A D, Please close the question by accepting the answer! Thanks..
0

Featured Post

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

How to sign a powershell script so you can prevent tampering, and only allow users to run authorised Powershell scripts
This article will help you understand what HashTables are and how to use them in PowerShell.
This tutorial will walk an individual through the process of transferring the five major, necessary Active Directory Roles, commonly referred to as the FSMO roles from a Windows Server 2008 domain controller to a Windows Server 2012 domain controlle…
This tutorial will walk an individual through the process of configuring their Windows Server 2012 domain controller to synchronize its time with a trusted, external resource. Use Google, Bing, or other preferred search engine to locate trusted NTP …

744 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