Friday, 15 August 2014

Exchange 2007 to 2013 Migration: Get-Content C:\userlist | New-MoveRequest -TargetDatabase "The operation couldn't be performed because object ' user' couldn't be found on 'dc.domain.local"

This post is not particularly a complex or interesting fix, I am posting it here for my own reference should I ever need to do something similar again. Who knows hopefully you find it useful too!
I was recently working on an Exchange 2007 to 2013 migration for a client and part of the project was to implement Database Availability Groups (DAG's) and segment mailboxes into Mailbox Databases by each department in the business. To do this I requested a list of users in each department from the client. The list had been generated by Active Directory and unfortunately all of the user names had a two space characters at the beginning of the string.

When I use the following command with the -Whatif switch to test my syntax and text file I receive an error.
Get-Content C:\Error.txt | New-MoveRequest –TargetDatabase “Mailbox Database” –Confirm:$false -Whatif

The operation couldn't be performed because object '  user' couldn't be found on 'dc.domain.local' this was because of the two space characters before each of the usernames in the C:\Error.txt file. 

I copied the lists of users over into an Excel spreadsheet, and used the following formula to remove the first two characters from the user name strings;
=RIGHT(A1, LEN (A1)-2)


This was in the column on the right of the user names, you can then drag the box down to populate all of the cells and the magic of Excel changes A1 to A2, A3,A4 etc. I then simply copy and pasted this back into a text file.


Now if I run the command again, the Exchange Shell does What if: Creating move request for each of the user accounts. If I were to remove the -Whatif­ switch, the Exchange Shell would begin migrating all of the users in the text file over to the new database.
Get-Content C:\Error.txt | New-MoveRequest –TargetDatabase “Mailbox Database” –Confirm:$false -Whatif