errors with input pipeline when executing Exchange 2007 MB movement script

Answered errors with input pipeline when executing Exchange 2007 MB movement script

  • Tuesday, November 20, 2012 5:11 AM
     
      Has Code

    Hi All,

    I am trying to move bulk users from a input file with alias and target having DB. The result should give the below things
    1. Send an email with users statistics before move.
    2. Move users to the target path
    3. Send an email after movement with user statistics & target path

    I am getting few errors with regard to the input pipeline. Can any one help me and let me know if we can still get a better colorful output in html format.

     $date = Get-Date -uformat "%Y%m%d" 
     $time = Get-Date -Format "HHmmss" 
     $MAIL_SERVER = "smtp.abc.com" 
     $FROM_ADDR = "ExchangeMBMovement@abc.com" 
     $TO_ADDR = "messagingsupport@abc.com" 
     $EMAIL_SUBJECT = "Batch mailbox movement details before movement - $date $time" 
     $EMAIL_SUBJECT = "Batch mailbox move completed - $date $time" 
     $REPORT_FILE_XML = "C:\Temp\migrations\" + $date + "_" + $time + "_mailboxmigrations.xml"  
     $REPORT_STATS_old = "C:\mbmove\" + $date + "_" + $time + "_MailboxStats_old.txt"  
     $REPORT_STATS_new = "C:\mbmove\" + $date + "_" + $time + "_MailboxStats_new.txt"  
      Import-CSV users.csv | Get-MailboxStatistics $_.alias | Format-Table -Property DisplayName,ServerName,StorageGroupName,DatabaseName,ItemCount,@{Expression={$_.TotalItemSize.Value.ToMB()};Label="Total Item Size (MB)"} -AutoSize | Out-File  $REPORT_STATS_old  
     Send-MailMessage -From $FROM_ADDR -To $TO_ADDR -Subject $EMAIL_SUBJECT1 -Body $EmailBody -Attachments $REPORT_FILE_XML,$tempReport -SmtpServer $MAIL_SERVER  
      Import-CSV users.csv | foreach {Get-Mailbox $_.alias | Move-Mailbox -MaxThreads 20 -BadItemLimit 1000 -confirm:$false  -TargetDatabase $_.target -ReportFile $REPORT_FILE_XML} 
     $EmailBody = "Processed mailbox moves for users in attached MailboxStats.txt file.`n" 
     $EmailBody += "********** Check attached log for details on success/failure. **********" 
     Import-CSV users.csv | Get-MailboxStatistics $_.alias | Format-Table -Property DisplayName,ServerName,StorageGroupName,DatabaseName,ItemCount,@{Expression={$_.TotalItemSize.Value.ToMB()};Label="Total Item Size (MB)"} -AutoSize | Out-File  $REPORT_STATS_New
     Send-MailMessage -From $FROM_ADDR -To $TO_ADDR -Subject $EMAIL_SUBJECT -Body $EmailBody -Attachments $REPORT_FILE_XML,$REPORT_STATS_New -SmtpServer $MAIL_SERVER  
      
     


    Ahmed Ali

All Replies

  • Tuesday, November 20, 2012 9:31 AM
     
     
    Can You show us what errors You get?
  • Tuesday, November 20, 2012 11:16 AM
     
     

    Hi 

    Here is the error

    Get-MailboxStatistics : The input object cannot be bound to any parameters for
    the command either because the command does not take pipeline input or the inpu
    t and its properties do not match any of the parameters that take pipeline inpu
    t.
    At C:\mbmove\test.ps1:11 char:47
    +   Import-CSV users.csv | Get-MailboxStatistics <<<<  $_.alias | Format-Table
    -Property DisplayName,ServerName,StorageGroupName,DatabaseName,ItemCount,@{Expr
    ession={$_.TotalItemSize.Value.ToMB()};Label="Total Item Size (MB)"} -AutoSize
    | Out-File  $REPORT_STATS_old
        + CategoryInfo          : InvalidArgument: (@{alias=user...02\MB12-2pri
       v1}:PSObject) [Get-MailboxStatistics], ParameterBindingException
        + FullyQualifiedErrorId : InputObjectNotBound,Microsoft.Exchange.Managemen
       t.MapiTasks.GetMailboxStatistics


    Ahmed Ali

  • Tuesday, November 20, 2012 11:51 AM
     
     Answered

    You typed this command wrong.

    You can't use $_ variable just in line. This is automatic variable used inside loops, scriptblocks and filters.

    You have to create one of these to use $_ variable. In this situation You have to create foreach loop with scriptblock:

    Import-CSV users.csv | Foreach { Get-MailboxStatistics $_.alias } | Format-Table ....

    • Marked As Answer by AhmedShaik Tuesday, November 20, 2012 1:34 PM
    •  
  • Tuesday, November 20, 2012 1:34 PM
     
     

    Perfectly working.

    Thanks


    Ahmed Ali