Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

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

Posted on 2016-10-05
8
Medium Priority
?
284 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:P S
  • 3
  • 2
8 Comments
 
LVL 40

Accepted Solution

by:
Subsun earned 2000 total points
ID: 41829995
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 35

Expert Comment

by:it_saige
ID: 41830066
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:P S
ID: 41831338
Thank you Subsun. It worked perfectly. You're AWESOME!!!
0
NFR key for Veeam Backup for Microsoft Office 365

Veeam is happy to provide a free NFR license (for 1 year, up to 10 users). This license allows for the non‑production use of Veeam Backup for Microsoft Office 365 in your home lab without any feature limitations.

 
LVL 40

Expert Comment

by:Subsun
ID: 41831504
You are welcome!
0
 

Author Comment

by:P S
ID: 41856670
This question can be closed. Thanks
0
 
LVL 40

Expert Comment

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

Featured Post

Get free NFR key for Veeam Availability Suite 9.5

Veeam is happy to provide a free NFR license (1 year, 2 sockets) to all certified IT Pros. The license allows for the non-production use of Veeam Availability Suite v9.5 in your home lab, without any feature limitations. It works for both VMware and Hyper-V environments

Question has a verified solution.

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

Let's recap what we learned from yesterday's Skyport Systems webinar.
In the absence of a fully-fledged GPO Management product like AGPM, the script in this article will provide you with a simple way to watch the domain (or a select OU) for GPOs changes and automatically take backups when policies are added, removed o…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…
There are cases when e.g. an IT administrator wants to have full access and view into selected mailboxes on Exchange server, directly from his own email account in Outlook or Outlook Web Access. This proves useful when for example administrator want…

927 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