including hash sign (#) inside of invoke-expression

This topic contains 1 reply, has 2 voices, and was last updated by Profile photo of Thom Schumacher Thom Schumacher 1 year ago.

  • Author
    Posts
  • #33397
    Profile photo of avishni
    avishni
    Participant

    Hello
    i need to start a program from a ps script that contains the hashsign (#) insilde the program parameters.
    can someone help me find the way to do this ?

    $command = 'c:\somecommand.exe -msg:text1 -number:#456852,4578684'
    $command
    $result= invoke-expression $command

    i believe that powershell see the # as comment and not reading anything after it

    Thanks

  • #33399
    Profile photo of Thom Schumacher
    Thom Schumacher
    Participant

    Use the backtick ` should produce what you see below:

    $command = 'echo test -number:`#12345678,45682'
    Invoke-Expression -Command $command
    

    test
    -number:
    #12345678
    45682

You must be logged in to reply to this topic.