CSV file and move mailbox
Hi There,
I have a csv file with the following content:
UserID,TargetDB
UserA,"ServerA\SGA\DB1"
Userb,"ServerA\SGB\DB2"
Userc,"ServerA\SGC\DB3"
And I'm trying to run a command:
Import-Csv .\users.txt | Move-Mailbox -Identity {$_.UserID} -TargetDatabase {$_.TargetDB}
But it fails with an error:
Move-Mailbox : Cannot bind parameter 'TargetDatabase'. Cannot convert the "$_.TargetDB" value of type "System.Managemet.Automation.ScriptBlock" to type "Microsoft.Exchange.Configuration.Tasks.DatabaseIdParameter".
I have tried these:
(Working just fine) Import-Csv .\users.txt | Get-Mailbox -Identity {$_.UserID}
(Working just fine) Import-Csv .\users.txt | Get-MailboxDatabase -Identity {$_.TargetDB}
The following didn't work either, with the same error:
Import-Csv .\users.txt | Get-Mailbox -Identity {$_.UserID} | Move-Mailbox -TargetDatabase {$_.TargetDB}
Is there a limits for the columns of the CSV file? Or what is wrong on this?
--
Petri
March 27th, 2010 3:07am
Does this work?
Import-Csv .\users.txt |%{ Move-Mailbox -Identity $_.UserID -TargetDatabase $_.TargetDB}
Free Windows Admin Tool Kit Click here and download it now
March 27th, 2010 5:57am
Try this
Import-CSV .\users.txt | % { Move-Mailbox -Identity $_.UserID -TargetDatabase $_.TargetDB}Santhosh Sivarajan | MCTS, MCSE (W2K3/W2K/NT4), MCSA (W2K3/W2K/MSG), CCNA, Network+
Houston, TX
http://blogs.sivarajan.com/
http://publications.sivarajan.com/
This posting is provided "AS IS" with no warranties, and confers no rights.
March 27th, 2010 6:33am
Great advice from both of you !! But may I ask what that %-sign does compared without it?
The operation was working, but that actually did not the work I though. I was trying to run that by multiple threads, but now it does it one by one. Any ideas to do so? I tried -maxThreads 3, but no success.
--
Petri
Free Windows Admin Tool Kit Click here and download it now
March 27th, 2010 10:57am
The % is PS shorthand for foreach-object, and would explain why it's singlethreading.
I'm not sure move-mailbox will multithread to on move to different targets in the same operation.
Try this:
Import-Csv .\users.txt |{ Move-Mailbox -Identity $_.UserID -TargetDatabase $_.TargetDB}
if that doesn't work you might try this:
Import-Csv .\users.txt | group targetdatabase | % {$mbxs = $_.group |% {$_.userid}$mbxs | Move-Mailbox -TargetDatabase $_.name}
I believe that will batch them up per targetdb.
March 27th, 2010 3:47pm
Thank you about explanation.
About the multithreading:
> Import-Csv .\users.txt |{ Move-Mailbox -Identity $_.UserID -TargetDatabase $_.TargetDB}
Gives and error:
Expressions are only permitted as the first element of a pipeline.
The other gives me:
Move-Mailbox : Cannot bind argument to parameter 'Identity' because it is null.
As "Move-Mailbox" requires identity, to whom be moved, it will not get it now.
Free Windows Admin Tool Kit Click here and download it now
March 29th, 2010 10:42am
On Mon, 29 Mar 2010 07:42:43 +0000, Petri X wrote:>>>Thank you about explanation. >> >>About the multithreading: >>> Import-Csv .\users.txt |{ Move-Mailbox -Identity $_.UserID -TargetDatabase $_.TargetDB} >>Gives and error: >>Expressions are only permitted as the first element of a pipeline. You're missing the "foreach" after the "|".>The other gives me: >>Move-Mailbox : Cannot bind argument to parameter 'Identity' because it is null. >>As "Move-Mailbox" requires identity, to whom be moved, it will not get it now. The "UserID" value in your CSV file isn't sufficiently qualified to beused as an identity. Try adding your AD domain name to (what I assumeare) the sAMAccountname values in the CSV. E.g., instead of "UserA",try "domain\UserA". Using the primary SMTP proxy address as the"UserID" will also work.---Rich MatheisenMCSE+I, Exchange MVP---
Rich Matheisen
MCSE+I, Exchange MVP
March 29th, 2010 6:59pm
Hi Richard,
Thank you for you advices.
>>> Import-Csv .\users.txt |{ Move-Mailbox -Identity $_.UserID -TargetDatabase $_.TargetDB} >> >>Gives and error: >> >>Expressions are only permitted as the first element of a pipeline. > >You're missing the "foreach" after the "|".
No I don't as the "foreach" or the "%" was the original answer for my question how to get all column out from the CSV into move-mailbox cmdlet. But as move-mailbox support multithreading operations, I would like to know how to get move more than single user at time (expect by starting multiple move-mailbox powershell's cmd-lets.
>>Move-Mailbox : Cannot bind argument to parameter 'Identity' because it is null. >> >>As "Move-Mailbox" requires identity, to whom be moved, it will not get it now. > > The "UserID" value in your CSV file isn't sufficiently qualified to be > used as an identity. Try adding your AD domain name to (what I assume > are) the sAMAccountname values in the CSV. E.g., instead of "UserA", > try "domain\UserA". Using the primary SMTP proxy address as the > "UserID" will also work.
On the error message it says "because it is null ". So the data is not invalid, as I'm able to move mailboxes one by one.
--
Petri
Free Windows Admin Tool Kit Click here and download it now
March 29th, 2010 10:34pm
On Mon, 29 Mar 2010 19:34:03 +0000, Petri X wrote:>>>> Import-Csv .\users.txt |{ Move-Mailbox -Identity $_.UserID -TargetDatabase $_.TargetDB} >> >>Gives and error: >> >>Expressions are only permitted as the first element of a pipeline. > >You're missing the "foreach" after the "|". >>No I don't as the "foreach" or the "%" was the original answer for my question how to get all column out from the CSV into move-mailbox cmdlet. But as move-mailbox support multithreading operations, I would like to know how to get move more than single user at time (expect by starting multiple move-mailbox powershell's cmd-lets. The foreach (or "%" or "foreach-object"), when it's presentimmediately after a "|" acts as a filter and will accept as manyobjects from the pipe as your setup allows. It's only when the foreachappears as the 1st command on a line that it works as a cmdlet.Regardless of whether it acts as a filter of cmdlet you can't pipeoutput into an expression.>>>Move-Mailbox : Cannot bind argument to parameter 'Identity' because it is null. >> >>As "Move-Mailbox" requires identity, to whom be moved, it will not get it now. > > The "UserID" value in your CSV file isn't sufficiently qualified to be > used as an identity. Try adding your AD domain name to (what I assume > are) the sAMAccountname values in the CSV. E.g., instead of "UserA", > try "domain\UserA". Using the primary SMTP proxy address as the > "UserID" will also work. >>On the error message it says "because it is null ". So the data is not invalid, as I'm able to move mailboxes one by one. Put the "foreach" in there.---Rich MatheisenMCSE+I, Exchange MVP---
Rich Matheisen
MCSE+I, Exchange MVP
March 30th, 2010 12:29am
See if this helps:
http://blogs.technet.com/benw/archive/2007/08/28/exchange-2007-advanced-move-mailbox-powershell-commands.aspx
get-mailbox seems more forgiving about what it will accept as an identity parameter, so this may work better with your data (not tested).
Import-Csv .\users.txt | group targetdatabase | % {$mbxs = $_.group |% {get-mailbox $_.userid}$mbxs | Move-Mailbox -TargetDatabase $_.name}
Free Windows Admin Tool Kit Click here and download it now
March 30th, 2010 12:48am