Solved

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

Posted on 2013-12-19
6
611 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 36

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
PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

 
LVL 36

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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

Disabling the Directory Sync Service Account in Office 365 will stop directory synchronization from working.
This article explains the steps required to use the default Photos screensaver to display branding/corporate images
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 to another domain controller. Log onto the new domain controller with a user account t…
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 …

809 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