?
Solved

PS Script that will list Name and OU of a user reading from a CSV of SamAccountnames.

Posted on 2013-12-19
6
Medium Priority
?
643 Views
Last Modified: 2013-12-23
I need a PS script that will read a CSV of SamAccountNames and list out the Users name and the OU they are in. Output should be a CSV. I.e.
 SamAccountname, Student Jones, Ou

the OUs are name simular to this.

Student-Male/Smith/11th/Users/s300/ourcity.countyedu.net

I have seen several PS scripts that will give the AD User properties but not sure how to modify them to read a CSV and then give the Full name and OU.

Thanks
0
Comment
Question by:Risrollout
  • 2
  • 2
  • 2
6 Comments
 
LVL 5

Accepted Solution

by:
Recept earned 1500 total points
ID: 39730815
The native Powershell way (requires a 2008+ Domain Controller). The OU output can be cleaned up if needed.
Import-Csv .\input.csv | ForEach-Object {Get-ADUser -Identity $_.SamAccountName -Properties * | Select-Object SamAccountName, Name, @{name="OU";expression={($_.DistinguishedName -split ",",2)[1]}}} | Export-Csv .\output.csv

Open in new window


Or the Quest AD Cmdlets way (requires Quest AD Cmdlets)
Import-Csv .\input.csv | ForEach-Object {Get-QADUser -Identity $_.SamAccountName | Select-Object SamAccountName, Name, @{name="OU";expression={$_.ParentContainerDN}}} | Export-Csv .\output.csv

Open in new window


The format of the .csv file should be
SamAccountName,
user1,
user2,

Open in new window

0
 
LVL 39

Expert Comment

by:Mahesh
ID: 39731150
Just try Bulk AD Users tool from Wisesoft

Within tool you can practically generate csv reports for any user properties (Through properties to Load option) in bulk and even can modify properties in bulk through csv update feature

http://www.wisesoft.co.uk/software/bulkadusers/default.aspx

Tool is freeware and can be registered as free

Mahesh
0
 

Author Comment

by:Risrollout
ID: 39732434
Thanks for the answers.
It looks like I did not give a good explanation of what we are trying to do with this. We are trying to pull information out of AD not add it.
 We have a software package that gives us a report that shows the login name of a person who logs into a PC and uses a piece of software( I.e. PhotoShop). That software does not have an AD connection nor do we want it to. We will take that report and pull out the login names (SamAccountname) and use that to pull the users Full Name and what OU they are in for another report. (could be several hundred names. The OUs tell us the School, HR teacher, Grade and so forth.)
So what we have is a CSV that looks like this.

S2013JoeB001,
S2013CheC001,

And looking for a Output CSV like this; SamAccountName, Full Name, OU.

S2013JoeB001,Joe Bass,Student-Male/Smith/11th/Users/s300/ourcity.countyedu.net.

PeterRecz,
When I try to run your line (we are running Windows 2008 R2 and have the AD Module for Win PS turned on) I get the output file created but no content. I do not quite understand how you have the input CSV structured

Hope this helps
.
0
Easily manage email signatures in Office 365

Managing email signatures in Office 365 can be a challenging task if you don't have the right tool. CodeTwo Email Signatures for Office 365 will help you implement a unified email signature look, no matter what email client is used by users. Test it for free!

 
LVL 39

Expert Comment

by:Mahesh
ID: 39734900
The above tool will give you output as u wanted
only OU output will be in LDAP format

There is option called "Properties to load" in software which will allow you to select any user property and also u can export the same in csv

You can pull users from entire domain, OU or from list of users if you have already

Mahesh
0
 
LVL 5

Expert Comment

by:Recept
ID: 39735099
Hi Risrollout,

Just to clarify the Powershell scripts will pull information out of AD, it won't add to it.

I've now attached an example csv file.
example.csv
0
 

Author Comment

by:Risrollout
ID: 39736826
PeterRecz,
The PS does not like the "{Get-ADUser -Identity" section. I get the error message

 "Get-ADUser : Cannot validate argument on parameter 'Identity'. The argument is null. Supply a non-null argument and try
 the command again.
0

Featured Post

The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

Question has a verified solution.

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

This process allows computer passwords to be managed and secured without using LAPS. This is an improvement on an existing process, enhanced to store password encrypted, instead of clear-text files within SQL
It’s time for spooky stories and consuming way too much sugar, including the many treats we’ve whipped for you in the world of tech. Check it out!
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…
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …

588 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