Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
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
?
633 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 37

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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 37

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

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

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.
Active Directory can easily get cluttered with unused service, user and computer accounts. In this article, I will show you the way I like to implement ADCleanup..
This tutorial will walk an individual through the steps necessary to join and promote the first Windows Server 2012 domain controller into an Active Directory environment running on Windows Server 2008. Determine the location of the FSMO roles by lo…
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 …

688 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