locked
wbadmin in powershell: ERROR - Command syntax incorrect. Error: Component'. See the command RRS feed

  • Question

  • Hello,

     I want to backup server from  powershell script:

    wbadmin start backup -backuptarget:\\?\Volume{3651776b-fc60-4ccb-af2b-48b702256f55} -hyperv:"ComputerName1,Host Component" -vssfull -quiet

    but I am gettting following error:

    ERROR - Command syntax incorrect. Error: Component'. See the command
    syntax below.

    In CMD it works fine but I am unable to get it working in PS. Can anyone help? Thank you.

    Pete


    sfs


    • Edited by fandango71 Sunday, November 30, 2014 12:49 AM
    Sunday, November 30, 2014 12:21 AM

Answers

  • Please see the following article for how to pass arguments for executables in PowerShell:

    Windows IT Pro: Running Executables in PowerShell

    Basically all you should need to do is quote the entire argument to the -backuptarget parameter, as in:


    "-backuptarget:\\?\Volume{3651776b-fc60-4ccb-af2b-48b702256f55}"

    You probably also need to quote the entire -hyperv argument as well:


    "-hyperv:ComputerName1,Host Component"

    You can use the ShowArgs.exe tool in the article download to see the actual command line that PowerShell is really passing to the executable.


    -- Bill Stewart [Bill_Stewart]

    • Edited by Bill_Stewart Sunday, November 30, 2014 2:25 PM
    • Marked as answer by fandango71 Monday, December 1, 2014 2:12 PM
    Sunday, November 30, 2014 2:20 PM

All replies

  • Try this:

    wbadmin 'start backup -backuptarget:\\?\Volume{3651776b-fc60-4ccb-af2b-48b702256f55} -hyperv:"ComputerName1,Host Component" -vssfull -quiet'


    ¯\_(ツ)_/¯

    Sunday, November 30, 2014 1:01 AM
  • It immediately shows up:

    Commands supported:

    ...

    So it doesnt recognize whatever follows after wbadmin.

    Pete


    sfs

    Sunday, November 30, 2014 3:02 AM
  • Last possibility

    #
    Start-Process -FilePath 'wbadmin.exe' -Argumentlist 'start backup -backuptarget:\\?\Volume{3651776b-fc60-4ccb-af2b-48b702256f55} -hyperv:"ComputerName1,Host Component" -vssfull -quiet'
    #


    ¯\_(ツ)_/¯

    Sunday, November 30, 2014 3:11 AM
  • Still the same. There is really no way how to pass the args to command? Or in another words: Why CMD can execure the command sucessfully? (btw tried also cmd /c in powershell but no luck)

    Pete


    sfs

    Sunday, November 30, 2014 3:39 AM
  • Your arguments are oviously wrong.

    i believe you need to remove the quotes.  I don't understand why you used them to begin with.


    ¯\_(ツ)_/¯

    Sunday, November 30, 2014 4:29 AM
  • Hi,

     tried to remove the quotes but no luck again. The quotes are there becuse CMD, which was used before cannot run the command without them.

    Pete


    sfs


    • Edited by fandango71 Sunday, November 30, 2014 1:58 PM
    Sunday, November 30, 2014 1:58 PM
  • This is PowerShell and not CMD.  You have an error in your arguments.  THe error si comming from the program and not PowerShell or CMD.


    ¯\_(ツ)_/¯

    Sunday, November 30, 2014 2:03 PM
  • Please see the following article for how to pass arguments for executables in PowerShell:

    Windows IT Pro: Running Executables in PowerShell

    Basically all you should need to do is quote the entire argument to the -backuptarget parameter, as in:


    "-backuptarget:\\?\Volume{3651776b-fc60-4ccb-af2b-48b702256f55}"

    You probably also need to quote the entire -hyperv argument as well:


    "-hyperv:ComputerName1,Host Component"

    You can use the ShowArgs.exe tool in the article download to see the actual command line that PowerShell is really passing to the executable.


    -- Bill Stewart [Bill_Stewart]

    • Edited by Bill_Stewart Sunday, November 30, 2014 2:25 PM
    • Marked as answer by fandango71 Monday, December 1, 2014 2:12 PM
    Sunday, November 30, 2014 2:20 PM
  • Placing the whole string is single quotes should have worked if the arguments are correct.

    I cannot find any example or documentation for -hyperv on 2012R2.


    ¯\_(ツ)_/¯

    Sunday, November 30, 2014 2:59 PM
  • If Bill's suggestion doesn't work or find a method then try the following approach.  This works often in complex quoting and switch arrangement situations.  It allows the Start-Process CmdLet to manage the assembly of the arguments.

    $alist=@(
        'start backup',
        '-backuptarget:\\?\Volume{3651776b-fc60-4ccb-af2b-48b702256f55}',
        '-hyperv:"ComputerName1,Host Component"',
        '-vssfull',
        '-quiet'
    )
    Start-Process -FilePath 'wbadmin.exe' -ArgumentList $alist
    

    There are also issues of Start-Process altering the arguments with spaces.  I have never found this to be an issue but others have complained about it.


    ¯\_(ツ)_/¯

    Sunday, November 30, 2014 3:05 PM
  • Nothing is mysterious anymore when you use  ShowArgs.exe (downloadable from the article). ShowArgs.exe does not do any interpretation of its command line (it does not use argc or argv but rather the GetCommandLine API), so if you use it in place of your executable, you can see the command line that PowerShell is really using.


    -- Bill Stewart [Bill_Stewart]

    Sunday, November 30, 2014 5:45 PM
  • Hi,

     your solution works, the problem was that whole args were not in quotes. Thank you both for advise.

    Pete


    sfs

    Monday, December 1, 2014 2:12 PM