I would switch to Export-Csv and then you can use Excel to do some of your 
munging.

Thanks,
Brian Desmond
br...@briandesmond.com<mailto:br...@briandesmond.com>

w - 312.625.1438 | c - 312.731.3132

From: Don Kuhlman [mailto:drkuhl...@yahoo.com]
Sent: Tuesday, April 2, 2013 10:22 AM
To: NT System Admin Issues
Subject: Powershell - match up user accounts from two ADs

Hi folks. I was asked to take a list of users from one AD and match them up to 
possible users in another AD.  The source and target Accounts were different in 
some cases so I couldn't search on the account value.  I thought using the last 
name was my best shot to get a match so that's what I searched on.

I needed their account from the target AD. The source list had their firstname, 
lastname, and AD account.  I needed to take the resulting list from the new AD 
and match those accounts to the source list of names to make sure I had the 
right user.

This script worked, but when I used it, I had to do some manual manipulation to 
pair up the results with the source users.  I also had to use notepad to clean 
up my output file and get rid of some extra format characters.

Anyone have any tips on a better way to do the search and limit the results ?


Thanks

Don K



Contents of my SourceUserlist.csv was just a subset with the last names - 
example:
kuhlman
smith
jones
...
..

Contents of the newuserlist.csv
@{SamAccountName=drkuhlman; Name=Don Kuhlman}
@{SamAccountName=jsmith; Name=John Smith}
@{SamAccountName=bsmith; Name=Bob Smith}
@{SamAccountName=rjones; Name=Bob Jones}
@{SamAccountName=djones; Name=Dick Jones}


SCRIPT is here:

# This script reads a list of surnames from a csv file 
\downloads\sourceuserlist.csv
# It then searches the current attached AD for any surnames matching
# And will write output to screen and newuserlist.csv the list of accounts and 
names found that match the searchstring


$path = "c:\downloads\sourceuserlist.csv"
$csv = import-csv -path $path
$table | set-content c:\downloads\newuserlist.csv


foreach($line in $csv) `

{

write-host $line.sn
$searchname = $line.sn
get-aduser -filter "sn -like '$searchname'" | select SamAccountName,Name| 
Add-Content c:\downloads\newuserlist.csv


}


~ Finally, powerful endpoint security that ISN'T a resource hog! ~
~ <http://www.sunbeltsoftware.com/Business/VIPRE-Enterprise/>  ~

---
To manage subscriptions click here: 
http://lyris.sunbelt-software.com/read/my_forums/
or send an email to 
listmana...@lyris.sunbeltsoftware.com<mailto:listmana...@lyris.sunbeltsoftware.com>
with the body: unsubscribe ntsysadmin

~ Finally, powerful endpoint security that ISN'T a resource hog! ~
~ <http://www.sunbeltsoftware.com/Business/VIPRE-Enterprise/>  ~

---
To manage subscriptions click here: 
http://lyris.sunbelt-software.com/read/my_forums/
or send an email to listmana...@lyris.sunbeltsoftware.com
with the body: unsubscribe ntsysadmin

Reply via email to