none
Schedule task for New-MigrationBatch RRS feed

  • Question

  • Hi All,

    Windows 2012+ Exchange 2013 CU10

    I follow this wiki:

    How to use Task Scheduler for Exchange scripts

    http://social.technet.microsoft.com/wiki/contents/articles/23150.how-to-use-task-scheduler-for-exchange-scripts.aspx

    to test a schedule task.

    I can run the example cmdlet in windows powershell:

     C:\Windows\System32\WindowsPowerShell\v1.0\Powershell.exe  -noExit -Command ".'C:\Program Files\Microsoft\Exchange Server\V15\Bin\RemoteExchange.ps1'; Connect-ExchangeServer -auto; Get-queue > c:\temp\queue.txt"

    But if I replace get-queue with New-MigrationBatch -Local -Name MigrationBatch1 -CSVData ([System.IO.File]::ReadAllBytes("D:\mailboxmove\mailboxlist.csv")) -TargetDatabases mdb01 -AutoStart -AutoComplete -NotificationEmails abc@contoso, it won't work. It says ")" is missing or similar error. Can someone give me a hint, thanks.


    <p style="margin:0cm 0cm 0pt"><span lang="EN-US" style="color:#0070c0; font-family:&quot;Segoe UI&quot;,&quot;sans-serif&quot;; font-size:10pt">Frank Wang<br/> TechNet Community Support</span></p> <p style="margin:0cm 0cm 0pt"><a href="http://blogs.technet.com/b/onescript" rel="nofollow"><img src="https://xnoegg.bay.livefilestore.com/y1plmwd9pFqoTZWcmr6-bsBuS7hTcNbr8YdT4WL3RRAuhDPVyUUOVchQt3EexNEBj4xYyornsD1kyLmtVqqsDfKv3PEEg9ejQzT/signature.jpg?psid=1" alt="" width="430" height="30.2"></a></p>

    Monday, November 23, 2015 9:54 AM

All replies

  • Hi,

    Could you share the exact command what you are currently trying with error details. From the above information it's very tough to give a hint where its specifically failed. While running the scipt put -verbose so that its easy to find out an error.

    As per the above details we need to add ; before starting the get-queue or new-migrationbatch, have you added in the script. Could you cross verify.

    Thanks for sharing the supporing link (Task Scheduler for Exchange scripts).


    • Edited by krselva Monday, November 23, 2015 1:20 PM
    Monday, November 23, 2015 1:18 PM
  • well, I ran the following cmdlet:

    C:\Windows\System32\WindowsPowerShell\v1.0\Powershell.exe -noExit -Command ".'C:\Program Files\Microsoft\Exchange Server\V15\Bin\RemoteExchange.ps1'; Connect-ExchangeServer -auto; New-MigrationBatch -Local -Name MigrationBatch1 -CSVData ([System.IO.File]::ReadAllBytes("D:\mailboxmove\mailboxlist.csv")) -TargetDatabases mdb01 -AutoStart -AutoComplete -NotificationEmails abc@contoso.com"

    Thanks.


    <p style="margin:0cm 0cm 0pt"><span lang="EN-US" style="color:#0070c0; font-family:&quot;Segoe UI&quot;,&quot;sans-serif&quot;; font-size:10pt">Frank Wang<br/> TechNet Community Support</span></p> <p style="margin:0cm 0cm 0pt"><a href="http://blogs.technet.com/b/onescript" rel="nofollow"><img src="https://xnoegg.bay.livefilestore.com/y1plmwd9pFqoTZWcmr6-bsBuS7hTcNbr8YdT4WL3RRAuhDPVyUUOVchQt3EexNEBj4xYyornsD1kyLmtVqqsDfKv3PEEg9ejQzT/signature.jpg?psid=1" alt="" width="430" height="30.2"></a></p>

    Tuesday, November 24, 2015 12:32 AM
  • Hi,

    According to your description, I understand you want to use Task Scheduler for Exchange scripts.
    First test your script or Exchange commands from the Exchange Management Shell.

    If it can't run there, it will certainly fail as a scheduled task. Secondly , also verify the commands or script can run from the RemoteExchange.ps1 environment using an elevated command prompt. 
    So please tell us the test results for further analysis.

    Regards,
    David 


    Tuesday, November 24, 2015 7:12 AM
    Moderator
  • PLEASE READ MY POST CAREFULLY. IF YOU HAVE NO ANSWER, PLEASE DON'T REPLY MY POST.

    <p style="margin:0cm 0cm 0pt"><span lang="EN-US" style="color:#0070c0; font-family:&quot;Segoe UI&quot;,&quot;sans-serif&quot;; font-size:10pt">Frank Wang<br/> TechNet Community Support</span></p> <p style="margin:0cm 0cm 0pt"><a href="http://blogs.technet.com/b/onescript" rel="nofollow"><img src="https://xnoegg.bay.livefilestore.com/y1plmwd9pFqoTZWcmr6-bsBuS7hTcNbr8YdT4WL3RRAuhDPVyUUOVchQt3EexNEBj4xYyornsD1kyLmtVqqsDfKv3PEEg9ejQzT/signature.jpg?psid=1" alt="" width="430" height="30.2"></a></p>


    • Edited by emma.yoyo Tuesday, November 24, 2015 7:48 AM
    Tuesday, November 24, 2015 7:47 AM
  • Hi,

    I would like to suggest few modifications on the script..

    Can u change the path from C:\Windows\System32\WindowsPowerShell\v1.0\Powershell.exe to powershell.exe

    powershell.exe -command specifically designs for running command line

    -Command
        Executes the specified commands (and any parameters) as though they were
        typed at the Windows PowerShell command prompt, and then exits, unless
        NoExit is specified. The value of Command can be "-", a string. or a
        script block.

        If the value of Command is "-", the command text is read from standard
        input.

        If the value of Command is a script block, the script block must be enclosed
        in braces ({}). You can specify a script block only when running PowerShell.ex
        in Windows PowerShell. The results of the script block are returned to the
        parent shell as deserialized XML objects, not live objects.

        If the value of Command is a string, Command must be the last parameter
        in the command , because any characters typed after the command are
        interpreted as the command arguments.

        To write a string that runs a Windows PowerShell command, use the format:
            "& {<command>}"
        where the quotation marks indicate a string and the invoke operator (&)
        causes the command to be executed.

    * could you intraduce braces from starting of the command and ending of the command 

    ('{C:\Program Files\Microsoft\Exchange Server\V15\Bin\RemoteExchange.ps1'; Connect-ExchangeServer -auto; New-MigrationBatch -Local -Name MigrationBatch1 -CSVData ([System.IO.File]::ReadAllBytes("D:\mailboxmove\mailboxlist.csv")) -TargetDatabases mdb01 -AutoStart -AutoComplete -NotificationEmails abc@contoso.com"})

    Please try the actual command in powershell and check.

    • Proposed as answer by krselva Monday, December 21, 2015 11:29 PM
    Monday, November 30, 2015 12:47 PM