none
Move Exchange mailboxes to O365 via PowerShell script RRS feed

  • Question

  • We are having a problem getting our scripting to work. We have to move 200-300 mailboxes (on a daily basis) to O365. This is an ongoing process. Currently we have over 700,000 mailboxes in the cloud. (Those numbers are correct.)

    We want to automate this process by exporting the list of mailboxes from the EMC (2010) to a CSV file.  Then to run a PS script within an Azure Active Directory PowerShell.

    Here is what we currently have ...

    ========================

    $cred = Get-Credential

    domain.com\<exchange-admin-account>
    <password>

    Import-Csv book1.csv | Select-Object -ExpandProperty `Alias' | foreach {New-MoveRequest -Remote -RemoteHostName 'webmail.domain.com' -RemoteCredential $cred -TargetDeliveryDomain 'service.domain.com' -verbose}

    ==============================

    There is a 'disconnect between the first two pipe segments from the last pipe segment.

    For example ... Import-Csv book1.csv | Select-Object -ExpandProperty 'Alias'  works well, and returns a list of the user alias' to the screen.

    Most of the last pipe segment works well, also. {New-MoveRequest -Remote -RemoteHostName 'webmail.domain.com' -RemoteCredential $cred -TargetDeliveryDomain 'service.domain.com' -verbose}     This portion work well for us.

     

    The 'disconnect' is that the data from the first portion does not translate into the variable to the actual MoveRequest. 

    Anyone have any ideas? What are we missing?

    Thank you in advance.

    Friday, January 3, 2014 6:24 PM

Answers

  • Does it work if you remove 'foreach' and  { }, as in:


    Import-Csv book1.csv | Select-Object -ExpandProperty Alias |
      New-MoveRequest -Remote -RemoteHostName 'webmail.domain.com' `
      -RemoteCredential $cred -TargetDeliveryDomain 'service.domain.com' `
      -verbose

    When you put the 'foreach' keyword on the right-hand side of a pipe (|), it sends each output object (in your example, alias names) to the code in between { } after the 'foreach' keyword. When the 'foreach' keyword is on the right-hand side of a pipe, it is really an alias for 'ForEach-Object'.

    If that does not work, then try it this way:


    Import-Csv book1.csv | Select-Object -ExpandProperty Alias | foreach-object {
      New-MoveRequest -Identity $_ -Remote -RemoteHostName 'webmail.domain.com' `
      -RemoteCredential $cred -TargetDeliveryDomain 'service.domain.com' `
      -verbose
    }
    

    In this case I am guessing that the alias from the CSV file would be the -Identity parameter of New-MoveRequest, so you would have to substitute the correct parameter name if it's not -Identity.

    Bill

    Friday, January 3, 2014 7:25 PM
    Moderator

All replies

  • Does it work if you remove 'foreach' and  { }, as in:


    Import-Csv book1.csv | Select-Object -ExpandProperty Alias |
      New-MoveRequest -Remote -RemoteHostName 'webmail.domain.com' `
      -RemoteCredential $cred -TargetDeliveryDomain 'service.domain.com' `
      -verbose

    When you put the 'foreach' keyword on the right-hand side of a pipe (|), it sends each output object (in your example, alias names) to the code in between { } after the 'foreach' keyword. When the 'foreach' keyword is on the right-hand side of a pipe, it is really an alias for 'ForEach-Object'.

    If that does not work, then try it this way:


    Import-Csv book1.csv | Select-Object -ExpandProperty Alias | foreach-object {
      New-MoveRequest -Identity $_ -Remote -RemoteHostName 'webmail.domain.com' `
      -RemoteCredential $cred -TargetDeliveryDomain 'service.domain.com' `
      -verbose
    }
    

    In this case I am guessing that the alias from the CSV file would be the -Identity parameter of New-MoveRequest, so you would have to substitute the correct parameter name if it's not -Identity.

    Bill

    Friday, January 3, 2014 7:25 PM
    Moderator
  • Thanks Bill,

    Your first suggestion worked well. That was exactly what we required. Many kudos to you.

    Monday, January 6, 2014 12:46 PM