Solved

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

Posted on 2013-12-19
6
603 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 500 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 35

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

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

Join & Write a Comment

As network administrators; we know how hard it is to track user’s login/logout using security event log (BTW it is harder now in windows 2008 because user name is always “N/A” in the grid), and most of us either get 3rd party tools, or just make our…
In this article, we will see the basic design consideration while designing a Multi-tenant web application in a simple manner. Though, many frameworks are available in the market to develop a multi - tenant application, but do they provide data, cod…
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 …

762 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

20 Experts available now in Live!

Get 1:1 Help Now