including hash sign (#) inside of invoke-expression

Welcome Forums General PowerShell Q&A including hash sign (#) inside of invoke-expression

This topic contains 1 reply, has 2 voices, and was last updated by

 
Participant
2 years, 10 months ago.

  • Author
    Posts
  • #33397

    Participant
    Points: 0
    Rank: Member

    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

    Participant
    Points: 36
    Rank: Member

    Use the backtick ` should produce what you see below:

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

    test
    -number:
    #12345678
    45682

The topic ‘including hash sign (#) inside of invoke-expression’ is closed to new replies.