Need help with script for building Exchange user migration list with aliases (Powershell)
I'm working on an Exchange migration project (2003 -> 2007 SP1) and am trying to build a script that does the following takes INPUT from a text file with display names (because display names is how the client thinks) - one per line and returns some kind of OUTPUT file that contains the alias/UPN for each user on the listI don't care about text, csv, whatever as long as it's in a format where I can massage it easily into a text file with one field being UPN. I have a (working) bulk migration script that takes a text file with one user alias per line and performs the migration, which is why I want something that gives me the alias/UPN in output. The UPNs are not in a consistent format, so I can't do string manipulation or take a best guess to build the list and deal with the exceptions as needed. My current code looks like this:$SourceFile = "c:\program files\microsoft\exchange server\scripts\displaynames.txt"$UserList = Get-Content $SourceFileforeach ($user in $UserList) { select name,displayname,samaccountname | Export-CSV c:\exch2007\migrate.csv -NoTypeInformation } I've worked through the dread "cannot find path "input file name" because it does not exist" error (when, of course, the file is RIGHT THERE). The script runs without errors and create the migrate.csv file, but the migrate.csv file is empty - 0 bytes. (this is the case whereever the output directory is ... I switched it to c:\program files\microsoft\exchange server\scripts to see if that made a difference). I'm a powershell newbie, so figure I must be doing something basically (or, with any luck, not-so-basically) wrong. Could someone please advise on my code and tell me what I need to fix to get actual output? If there's a more robust way to get the output (say, with the >> operator), please let me know. many thanks in advance,Charlotte
January 29th, 2010 3:19am

Try this:$usercsv = @()foreach ($user in $UserList) { $rec = $_ | select name,displayname,samaccountname $usercsv += $rec }$usercsv | Export-CSV c:\exch2007\migrate.csv -NoTypeInformation }
Free Windows Admin Tool Kit Click here and download it now
January 29th, 2010 5:53am

Actually, I don't think that's going to work. If all that's in your list is a display name, then you need something like this:$usercsv = @()foreach ($user in $UserList) { $rec = get-user $_ | select name,displayname,samaccountname $usercsv += $rec }$usercsv | Export-CSV c:\exch2007\migrate.csv -NoTypeInformation
January 29th, 2010 6:00am

On Fri, 29-Jan-10 00:19:04 GMT, Charlotte in Berkeley wrote:>>>I'm working on an Exchange migration project (2003 -> 2007 SP1) and am trying to build a script that does the following takes INPUT from a text file with display names (because display names is how the client thinks) - one per line and returns some kind of OUTPUT file that contains the alias/UPN for each user on the listI don't care about text, csv, whatever as long as it's in a format where I can massage it easily into a text file with one field being UPN. I have a (working) bulk migration script that takes a text file with one user alias per line and performs the migration, which is why I want something that gives me the alias/UPN in output. The UPNs are not in a consistent format, so I can't do string manipulation or take a best guess to build the list and deal with the exceptions as needed. My current code looks like this:$SourceFile = "c:\program files\microsoft\exchange server\scripts\displaynames.txt"$UserList = Get-Content $SourceFileforeach ($user in $UserList) {>select name,displayname,samaccountname | Export-CSV c:\exch2007\migrate.csv -NoTypeInformation } This works:get-content displaynames.txt | get-user | selectname,displayname,samaccountname,userprincipalname | export-csvtest.csv -notypeinfo>I've worked through the dread "cannot find path "input file name" because it does not exist" error (when, of course, the file is RIGHT THERE).Is the current directory "c:\program files\microsoft\exchangeserver\scripts"? I'd probably create another directory beneath theroot of the drive and work from there.---Rich MatheisenMCSE+I, Exchange MVP --- Rich Matheisen MCSE+I, Exchange MVP
Free Windows Admin Tool Kit Click here and download it now
January 29th, 2010 6:21am

Rich, that rewrite worked perfectly. Thank you!*bookmarking page for future reference*Yes, I had put everything in exchange server\scripts. I had originally started in a subdir off c: and was running into "cannot find path", so moved it all into exchange server\scripts to see if it was some weird permissions issue in 2008.(Um, err, it's possible that the path issues were because I forgot to select "all file types" in notepad so there were extra .txt extensions floating around. *embarrassed* I really don't like the default file view on server 2008 but hadn't gotten around to configuring the SHOW ME ALL THE EXTENSIONS, I REALLY DO WANT TO SEE THEM yet. So I will move the show back over out of the Exchange directories and re-try, now that my output is what I want.)Thanks again!Charlotte
January 30th, 2010 12:07am

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics