locked
Space character in argument of a native command in powershell console RRS feed

  • Question

  • Hello PS gurus!

    Here's my problem

    The command I use :

    invoke-expression "dfsradmin mem list /rgname:"replication groupname" /attr:memname"

    Error output :

    Invoke-Expression : A positional parameter cannot be found that accepts argument 'replication'.

    I've tried with double-quote, doubling the double quote, with escape character, etc... nothing works ....

    But if I run the same command in cmd.exe, it works fine.

    What would be the correct syntax to get powershell to understand what I want ?

    Thank you!!

    Tuesday, October 18, 2011 3:39 PM

Answers

  • $RG = "Batch File Replication"
    Start-Process dfsradmin  -ArgumentList "mem","list","/rgname:`"$RG`"","/attr:memname" -NoNewWindow
    

    • Marked as answer by DavidJob Tuesday, October 18, 2011 5:33 PM
    Tuesday, October 18, 2011 5:20 PM

All replies

  • invoke-expression 'dfsradmin mem list /rgname:"replication groupname" /attr:memname'


    [string](0..33|%{[char][int](46+("686552495351636652556262185355647068516270555358646562655775 0645570").substring(($_*2),2))})-replace " "
    Tuesday, October 18, 2011 3:43 PM
  • Hello, mjolinor and thank you!

    Intersting ... now, I get passed the powershell error  ... but ... now it is dfsradmin that do not work ...

    PS C:\invoke-expression 'dfsradmin mem list /rgname:"replication groupname" /attr:memname'

    Failed:
    The subobject "/rgname:replication is not a valid subobject.

    We can see that the arg is trunked at the space character...

    Still, this work in cmd.exe
    dfsradmin mem list /rgname:"replication groupname" /attr:memname

    Weird .... More ideas ?

    Thx again


    -David Job
    Tuesday, October 18, 2011 3:54 PM
  • Try this without iex:

    dfsradmin mem list /rgname:`"replication groupname`" /attr:memname
    

    Tuesday, October 18, 2011 4:16 PM
  • Hello!

    You're right that this work as is ... but as soon as I want to automate this with variables like :

    $RG = "Batch File Replication"
    dfsradmin mem list /rgname:`"$RG`" /attr:memname

    OR

    dfsradmin mem list /rgname:$RG /attr:memname

    It fails with the same error

    Failed:
    The subobject "/rgname:"Batch is not a valid subobject.

    ... I'm really clueless!

    Thx!


    -David Job
    Tuesday, October 18, 2011 4:35 PM
  • dfsradmin mem list /rgname:"'$RG'" /attr:memname

    • Edited by Kazun Tuesday, October 18, 2011 4:53 PM
    Tuesday, October 18, 2011 4:53 PM
  • No luck,

    same error .... :((

    Thx for your effort ...


    -David Job
    Tuesday, October 18, 2011 5:00 PM
  • $RG = "Batch File Replication"
    Start-Process dfsradmin  -ArgumentList "mem","list","/rgname:`"$RG`"","/attr:memname" -NoNewWindow
    

    • Marked as answer by DavidJob Tuesday, October 18, 2011 5:33 PM
    Tuesday, October 18, 2011 5:20 PM
  • Woah!

    What a workaround you got!

    But hey, it works ;-)

    Thank you kazun


    -David Job
    Tuesday, October 18, 2011 5:33 PM
  • Should there be a -Wait switch parameter added to the Start-Process command?

    On 10/18/2011 12:20 PM, Kazun [MVP] wrote:

    $RG = "Batch File Replication"
    Start-Process dfsradmin    -ArgumentList "mem","list","/rgname:`"$RG`"","/attr:memname" -NoNewWindow


    Tuesday, October 18, 2011 7:13 PM